[英]CakePHP redirect in a class
我已經寫了一個插件類,我想在其中進行重定向,但是不起作用。 我該如何解決? 這是我在插件控制器內的調用:
public function action(){
$permissions = new Permissions();
$rules = array('some_value');
$permissions->allow($rules);
}
這是我的課:
class Permissions {
public function __construct(array $settings = array()) {
}
public function allow($rules) {
//some check
$this->redirect('/');
}
}
這段代碼向我返回此錯誤:
Fatal error: Call to undefined method Permissions::redirect()
你可以嘗試一下,我沒有嘗試但是可以
public function allow($rules) {
//some check
Router::redirect(
'/home/*',
array('controller' => 'index', 'action' => 'index')
);
}
如果那是您的類的確切代碼,那么您不能使用$this->redirect('/');
是因為您的類沒有擴展其他任何類,因此也沒有繼承這些函數。
它看起來應該像這樣:
class PermissionsController extends PermissionsPluginAppController {
public function __construct(array $settings = array()) {
}
public function allow($rules) {
//some check
$this->redirect('/');
}
}
請參閱此處的文檔: http : //book.cakephp.org/2.0/en/plugins.html#plugin-controllers
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.