cakephp 中的多重重定向

Multiple redirect in cakephp

我想重定向到两个页面,一个是视图部分,另一个是索引部分。

示例 : 我要添加新用户。在我点击提交按钮之后。 该页面直接指向新选项卡中的索引页面,另外一个重定向是视图部分。目前它只重定向到索引函数。我想重新定位到两个单独的索引和视图函数,否则弹出 window 。

控制器:

 public function add() {
            if ($this->request->is('post')) {
                $this->User->create();
                if ($this->User->save($this->request->data)) {
                    $this->Session->setFlash(__('The user has been saved'));
                    $this->redirect(array('action' => 'index'));
                } else {
                    $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
                }
            }
        }

查看:

<div id="content">
    <div id="flashMessage" class="message">The user could not be saved. Please, try again.</div>
    <div class="users form">
        <form action="/login/users/add" id="UserAddForm" method="post" accept-charset="utf-8">
        <div style="display:none;">
            <input type="hidden" name="_method" value="POST">
        </div>
        <fieldset>
            <legend>Add User</legend>
            <div class="input text required">
                <label for="UserUsername">Username</label>
                <input name="data[User][username]" maxlength="128" type="text" value="admin@vtu.ac.in" id="UserUsername">
            </div>
            <div class="input password required">
                <label for="UserPassword">Password</label>
                <input name="data[User][password]" type="password" value="vtuadmin" id="UserPassword">
            </div>
            <div class="input text required">
                <label for="UserRole">Role</label>
                <input name="data[User][role]" maxlength="20" type="text" value="admin" id="UserRole">
            </div>
            <div class="input text required error">
                <label for="UserRole1">Role1</label>
                <input name="data[User][role1]" type="text" value="" id="UserRole1" class="form-error">
                <div class="error-message">Please enter a valid role11111</div>
            </div>
        </fieldset>
        <input type="submit">
        </form>
    </div>
</div>

试试这个:

控制器:

public function add() {
        if ($this->request->is('post')) {
            $flag='0';
            $this->User->create();
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('The user has been saved'));
                $flag='1';
                $this->set(compact('flag'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
            }
        }
    }

查看:

if($flag == 1){
  //Use Jquery window.open()/
}

window.open ref link 是:Click me