//授标主任
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'));
}
}
}
}//前提控制器
<?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上的成员函数头()。任何保证
发布于 2015-05-06 05:41:26
我想出了窍门。//授标主任
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'));
}
}
}
}//许可控制器
<?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地址就可以重定向,并将其从授予控制器本身重定向。
https://stackoverflow.com/questions/30067216
复制相似问题