PHP code example of josegonzalez / cakephp-simple-scope

1. Go to this page and download the library: Download josegonzalez/cakephp-simple-scope library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

josegonzalez / cakephp-simple-scope example snippets



App::uses('Model', 'Model');

class AppModel extends Model
{
    public $actsAs = array('SimpleScope.Scope');
}


App::uses('AppModel', 'Model');

class User extends AppModel
{
    public $scopes = array(
        'active_admin' => array(
            'name' => 'Active admin users',
            'find' => array(
                'type' => 'list',
                'virtualFields' => array(
                    'fullname' => "CONCAT(User.firstname, ' ', User.lastname)"
                ),
                'options' => array(
                    'fields' => array('User.id', 'User.fullname'),
                    'conditions' => array('User.role LIKE' => '%admin%'),
                    'order' => array('User.fullname'),
                ),
            ),
        ),
    );
}


$activeUsers = $this->User->scopedFind('active_admin');


$activeUsers = $this->User->find('active_admin');


scopes = $this->User->scopes();