覆盖AppController中的重定向

时间:2015-02-28 10:27:06

标签: php cakephp redirect override

我想覆盖"重定向"插入语言前缀。为此,我已将此添加到AppController.php

public function redirect( $url, $status = NULL, $exit = true ) {
    die(debug('$url'));
    if (!isset($url['language']) && $this->Session->check('Config.language')) {
        $url['language'] = $this->Session->read('Config.language');
    }
    parent::redirect($url,$status,$exit);
}

显然die(..)仅用于测试是否调用此函数。

我的控制器代码:

public function add() {
    if ($this->request->is('post')) {
        $this->request->data['Party']['language_id'] = $this->Session->read('Config.LanguageId');
        $this->Party->create();
        if ($this->Party->save($this->request->data)) {
            $this->Session->write('partyId', $this->Party->id);
            return $this->redirect(array(
                'controller' => 'parties',
                'action' => 'editGuestlist',
            ));
        } else {
            $this->Session->setFlash(__('The party could not be saved. Please, try again.'));
        }
    }
}

我预计" $ this->重定向"在XyzController中将调用我的公共函数"重定向"在AppController中。

如果我要添加一个聚会,我将被重定向到/ parties / editGuestlist,不会添加任何前缀,代码也不会停止。所以很明显,我的压倒一切都没有用。因为我是cakephp的新手,我希望有人可以向我解释这种行为。

更新

我在/config/routes.php中发现了一个修复了该行为的错误,但我仍然不知道为什么我的覆盖函数根本没有被调用。

我已添加数组('语言' =>' [a-z] {3}')

    Router::connect('/:language/:controller/:action/*',
        array(),
        array('language' => '[a-z]{3}')
    );

0 个答案:

没有答案
相关问题