首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cakephp重定向是在null上对成员函数头()进行错误调用。

问Cakephp重定向是在null上对成员函数头()进行错误调用。
EN

Stack Overflow用户
提问于 2015-05-06 03:55:37
回答 1查看 1.3K关注 0票数 1

//授标主任

代码语言:javascript
复制
App::import('Controller', 'Permissions');
        class AwardsController extends AppController {
        public function add($id=NULL) {
            if (!$id) {
                throw new NotFoundException(__('Invalid User'));
            }
            if(!$this->Session->check('Auth.User')){
                $this->redirect(array('controller'=>'users','action' => 'login'));      
            }else{
                $Permission= new PermissionsController;
                if($Permission->isAuth($id)){
                    if ($this->request->is('post')) {
                        $this->Award->create();
                        $this->request->data['Award'][0]['basicprofile_id']=10;
                        var_dump($this->data);
                        if ($this->Award->saveAll($this->request->data['Award'])) {
                            $this->Session->setFlash(__('Award has been added '));
                            //$Permission= new PermissionsController;
                            //$this->redirect(array('controller'=>'users','action' => 'login'));
                            $Permission->redirectProfile($id);
                        } else {
                            $this->set('error',sizeof($this->request->data['Award']));
                            $this->Session->setFlash(__('The award has not added. Please, try again.'));
                        }   
                    }
                }else{
                    $this->Session->setFlash(__('You are not authorized to access it'));
                    $this->redirect(array('controller'=>'users','action' => 'login'));
                }
            }
        }
    }

//前提控制器

代码语言:javascript
复制
 <?php

        class PermissionsController extends AppController {


        public function redirectProfile($id){
            if(AuthComponent::user('role')=='Admin'){echo "working";
                $this->redirect(array('controller'=>'users','action' => 'index'));
            }else if(AuthComponent::user('role')=='Teacher'){
                //$this->redirect(array('controller'=>'profiles','action' => 'teacher', $id));
            }
        }
    }

    ?>

在权限控制器中,echo正在打印,但是url的重选会给出致命的错误:调用null上的成员函数头()。任何保证

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-06 05:41:26

我想出了窍门。//授标主任

代码语言:javascript
复制
App::import('Controller', 'Permissions');
        class AwardsController extends AppController {
        public function add($id=NULL) {
            if (!$id) {
                throw new NotFoundException(__('Invalid User'));
            }
            if(!$this->Session->check('Auth.User')){
                $this->redirect(array('controller'=>'users','action' => 'login'));      
            }else{
                $Permission= new PermissionsController;
                if($Permission->isAuth($id)){
                    if ($this->request->is('post')) {
                        $this->Award->create();
                        $this->request->data['Award'][0]['basicprofile_id']=10;
                        var_dump($this->data);
                        if ($this->Award->saveAll($this->request->data['Award'])) {
                            $this->Session->setFlash(__('Award has been added '));
                            //$Permission= new PermissionsController;
                            //$this->redirect(array('controller'=>'users','action' => 'login'));
                            $this->redirect($Permission->redirectProfile($id));
                        } else {
                            $this->set('error',sizeof($this->request->data['Award']));
                            $this->Session->setFlash(__('The award has not added. Please, try again.'));
                        }   
                    }
                }else{
                    $this->Session->setFlash(__('You are not authorized to access it'));
                    $this->redirect(array('controller'=>'users','action' => 'login'));
                }
            }
        }
    }

//许可控制器

代码语言:javascript
复制
<?php

  class PermissionsController extends AppController {
public function redirectProfile($id){
            if(AuthComponent::user('role')=='Admin'){echo "working";
                return (array('controller'=>'users','action' => 'index'));
            }else if(AuthComponent::user('role')=='Teacher'){
                return (array('controller'=>'profiles','action' => 'teacher', $id));
            }
        }
    }

    ?>

只需返回url地址就可以重定向,并将其从授予控制器本身重定向。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30067216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档