PHP code example of k1low / model_alias

1. Go to this page and download the library: Download k1low/model_alias 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/ */

    

k1low / model_alias example snippets



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

/**
 * Application level Controller
 *
 */
class AppController extends Controller
{
    use ModelAliasTrait;

    public function __construct($request = null, $response = null)
    {
        // ModelAliasTrait
        $this->initUsesAlias();
        parent::__construct($request, $response);
    }

    public function loadModel($modelClass = null, $id = null)
    {
        // ModelAliasTrait
        return $this->loadAliasModel($modelClass, $id);
    }
}



class AdminUsersController extends AppController
{
    public $uses = [
        'User' => ['className' => 'AdminUser'],
    ];

    public function view($id = null)
    {
        $this->set(['user' => $this->User->view($id)]);
    }
}