我想重定向到两个页面,一个是视图部分,另一个是索引部分。
示例:我要添加新用户。点击提交按钮后。 该页面在新选项卡中具有直接索引页面,另一个重定向是视图部分。目前它的重定向仅为索引功能。我想在两个单独的或弹出窗口中重新定义索引和视图函数。
控制器:
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>
答案 0 :(得分:2)
试试这个:
<强>控制器:强>
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引用链接是:Click me