重复的AppController cakephp

时间:2014-09-28 15:37:47

标签: php cakephp

对于我的网站我需要有两个不同的auth会话,因为一个登录是针对管理部分(如worpdress admin“wp-admi”访问),一个登录是用于登录该网站的帐户。

所以我曾想过用AppAdminController复制AppController,但我找回了一些错误。

这是我的AppAdminController

App::uses('Controller', 'Controller');
class AppAdminController extends Controller {
    public $helpers = array('Html', 'Form', 'Session'); //'DebugKit.Toolbar'
    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'admin', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'admin', 'action' => 'index'),
            'authError' => 'Questa risorsa non sembra appartenere al tuo account, oppure non hai eseguito l\'accesso',
            'autoRedirect' => false,
            'authorize' => array(
                'Controller',
                'Actions' => array(
                    'actionPath' => 'controllers'
                )
            ),
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'username')
                )
            )
        )
    );

    public function afterFilter () {

    }

    public function beforeFilter () {

    }
}

我将它用于AdminController:

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

class AdminController extends AppAdminController {
    public $name = 'Admin';
    public $scaffold;
    public $uses = 'users';
    public $useDbConfig = 'admin';

    public function beforeFilter () {
        parent::beforeFilter(); 

        $user_type = 'guest';

        if($this->Session->read('is_logged')){
            $auth_user = $this->Auth->user();
            $user_type = $auth_user['group'];
        }

    }
}

我检索到这个错误:

Call to a member function read() on a non-object

进入这一行:

if($this->Session->read('is_logged')){

我该如何解决这个问题?

由于

0 个答案:

没有答案