duanchun1852 2015-02-26 06:00
浏览 74
已采纳

在cakephp中进行多次重定向

I want redirect to two pages one is view part another one is index part .

Example : I am going to add new user. After i click submit button . The page has direct to index page in new tab and one more redirect is view part . Currently its redirect to only index function . I want to reidrect to both index and view function in two separate or else in pop up window .

Controller:

 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.'));
                }
            }
        }

View:

<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>
  • 写回答

1条回答 默认 最新

  • doujiao3998 2015-02-26 08:46
    关注

    Try This :

    Controller:

    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.'));
                }
            }
        }
    

    View:

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

    window.open ref link is : Click me

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器