CakePHP重定向循环

时间:2012-12-04 21:13:01

标签: cakephp redirect

我的代码中出现了最奇怪的Cake错误。当下面的代码调用add()方法(也在这里和另一个控制器中重现)时,代码会将302重新定向的HTTP代码重定向到edit()动作(实质上,对于用户来说,它看起来好像什么都没有发生)。更复杂的是,当我不在该页面上时调用相同的URL(尽管页面不相互依赖),我被重定向到我的应用程序的基础,这导致重定向循环。我尝试从这个控制器调用其他方法(使用正确的参数)来查看这是否只是add()动作的问题,但我得到了相同的重定向循环。我已经检查了所有的SE,但找不到相关的答案。

以下是相关代码:

function edit($id=null) {
 if(!$id) {
    $this->Session->setFlash('Invalid!');
    $this->redirect(array(
        'action' => 'index')
        );

 }
 else {
     //Get the slides themselves
    $slides = $this->Slide->find('all', array('conditions' => array('Slide.module_id' => $id)));
    $this->set('slides', $slides);
    //Get the data for the Module
    $module = $this->Module->find('first',
            array(
                'conditions' => array (
                    'Module.id' => $id
                ),
                'fields' => array(
                    'Module.module_name',
                    'Module.id')
            )
        );
 }
 }

这是add()代码(同样来自不同的模块):

    function add($module = null) {
        if ($this->request->is('get')) {
                        //Set some variables for the view (this code I know works as it has been used successfully elsewhere
        } 
        else { //User is POSTing
        $this->Slide->create();
        $this->Slide->save($this->data);
        }
    }

提前感谢大家;没有你的支持,我无法做到这一点!

编辑:这是AppController代码:

public $components = array(
    'Auth' => array(
        'authorize' => array(
            'Actions' => array('actionPath' => 'controllers')
            ),
    'loginAction' => array(
        'controller' => 'users',
        'action' => 'login'
        ),
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'email')
             )
        ),
    'logoutRedirect' => array('/')          
    ),
    'Session'
);
public $helpers = array('Html', 'Form', 'Session');
public function isAuthorized() {
    return true;
}
public function Controller() {

}

}

0 个答案:

没有答案