Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Define a namespace You will be using
- */
- namespace App\Test;
- /**
- * Include all classes You used to use
- */
- use Table\UsersTable;
- use Controller;
- /**
- * Controllers\PagesController.php
- *
- * Class PagesController
- * @package App\Test
- * @property UsersTable $Users
- */
- class PagesController extends Controller
- {
- /**
- * Initializing Models and additional configurations
- */
- public function initialize()
- {
- $this->loadModel('Users');
- }
- /**
- * Fetching users list and passing it to View
- */
- public function index()
- {
- $this->set('users', $this->Users->getAllUsers());
- // OR
- $users = $this->Users->getAllUsers();
- $this->set(compact('users'));
- }
- }
- /**
- * Models\UsersTable.php
- *
- * Class UsersTable
- * @package App\Test
- */
- class UsersTable extends Table
- {
- /**
- * Returns all users list
- * @param $order string asc|desc
- * @param $field string
- * @return array
- */
- public function getAllUsers($order = 'asc', $field = 'id')
- {
- return $this->find('all')
- ->order([$field => $order])
- ->toArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment