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

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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历