k1low/model_alias

ModelAlias

Fund package maintenance!
k1LoW

Installs: 3 483

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

0.0.4 2015-03-09 07:41 UTC

This package is auto-updated.

Last update: 2024-11-06 09:45:20 UTC


README

Use alias in Controller::uses

<?php
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);
    }
}
<?php

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

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