脚本宝典收集整理的这篇文章主要介绍了CakePHP:调用成员函数allow(),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP class ProtectedController extends AppController { public $components = array( 'Session','Auth' => array( 'loginredirect' => array('controller' => 'home','action' => 'index'),'logoutRedirect' => array('controller' => 'home','action' => 'index') ) ); public $paginate = array( 'limIT' => 2 ); public function beforeFilter() { $this->Auth->allow('index','view'); } }
AppController的
App::uses('Controller','Controller'); class AppController extends Controller { }
UsersController
<?PHP App::uses('ProtectedController','Controller'); class UsersController extends ProtectedController { public function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('add','logout'); } }
我一直在
Fatal error Error: Call to a member function allow() on a non-object File: /Library/WebServer/Documents/cakePHP_stats/app/Controller/ProtectedController.PHP Line: 18 Notice: If you want to customize this error message,create app/View/Errors/fatal_error.ctp
现在的错误.
有人如何解决这个问题.从我看到它应该加载ProtectedController组件和AuthComponent将被加载.
编辑:
第18行是ProtectedController的这个:
public function beforeFilter() { $this->Auth->allow('index','view'); }
编辑:
我现在唯一能做的就是削减这个:
public $components = array( 'Session','Auth' => array( 'LOGinRedirect' => array('controller' => 'home','action' => 'index') ) );
到AppController然后覆盖然后允许每个人:
class AppController extends Controller { public $components = array( 'Session','action' => 'index') ) ); public function beforeFilter() { $this->Auth->allow('*'); } }
>我的AppController也包含Auth组件,并在其beforeFilter中执行$this-> Auth-> allow().
>我的ProtectedController没有声明login / logoutRedirects,并调用其父级的beforeFilter.
>我的UsersController根本不扩展ProtectedController.我的受保护控制器只包含Auth组件并调用其父级的beforeFilter.
只是推测:如果未经授权的人试图访问受保护的资源,默认的Auth组件会重定向到/ users / login.当您保护UsersController并且不允许登录操作时,这可能会导致您遇到的行为.
以上是脚本宝典为你收集整理的CakePHP:调用成员函数allow()全部内容,希望文章能够帮你解决CakePHP:调用成员函数allow()所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。