帮忙帮下 流程问题 不知道要怎么处理 麻烦各位
本帖最后由 星辰大海 于 2014-3-4 15:22 编辑My_Controller.php
<?phpif ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hantech_Controller extends CI_Controller {
private $msg = array();
public function __construct() {
parent::__construct();
}
/**
* 输出信息类型
* @return
*/
public function outPageInfo ($data=null) {
if ($this->input->is_ajax_request()) {
echo json_encode($data);
} else {
$this->load->view('Public/Info');
exit();
}
}
}
class Auth_Controller extends Hantech_Controller {
public function __construct() {
parent::__construct();
$this->checkAuthInfo();
}
/**
* 验证用户登录 权限
* @return
*/
public function checkAuthInfo() {
$this->load->library('auth');
if ( !$this->auth->checkAuthInfo() ) {
$this->msg = $this->auth->getErrorInfo();
$this->outPageInfo();
}
}
}
actionAction.php
<?phpif ( ! defined('BASEPATH')) exit('No direct script access allowed');
class IndexAction extends Auth_Controller {
public function Index () {
echo 1;
}
}
1访问IndexAction/Index
2Auth_Controller类 checkAuthInfo 方法判断没有权限
3调用 Hantech_Controller 类outPageInfo方法
4判断非ajax请求 输出模版 exit();
问题 1 模版内容不出现
2 exit注释后可以输出模版Index方法执行了
需求 1 输出模版 停止访问IndexAction类 Index方法
Hex 发表于 2014-3-4 15:23 static/image/common/back.gif
控制器中不能使用 exit,必须使用 return,因为 CI 要在你的函数结束后做很多其他事情。
可以试试 _remap...
解决了谢谢 _remap
class Auth_Controller extends Hantech_Controller {
public function __construct() {
parent::__construct();
$this->checkAuthInfo();
}
public function _remap($method)
{
if ($this->flag) {
$this->$method();
} else {
if ($this->input->is_ajax_request()) {
echo json_encode();
} else {
$this->load->view('Public/Info');
}
}
}
/**
* 验证用户登录 权限
* @return
*/
public function checkAuthInfo() {
$this->load->library('auth');
if ( !$this->auth->checkAuthInfo() ) {
$this->msg = $this->auth->getErrorInfo();
$this->flag = false;
}
}
}
本帖最后由 星辰大海 于 2014-3-4 15:23 编辑
帮帮忙 谢谢
控制器中不能使用 exit,必须使用 return,因为 CI 要在你的函数结束后做很多其他事情。
可以试试 _remap 方法来实现中断 index 方法执行的效果,具体可以看下手册控制器章节。 Hex 发表于 2014-3-4 15:23 static/image/common/back.gif
控制器中不能使用 exit,必须使用 return,因为 CI 要在你的函数结束后做很多其他事情。
另外,你可能需要 ...
如果每个都去添加判断 就太麻烦了 还是感谢
我的C里经常exit啊
莫非父类里不能exit 星辰大海 发表于 2014-3-4 15:26 static/image/common/back.gif
如果每个都去添加判断 就太麻烦了 还是感谢
可以试试 _remap 方法来实现中断 index 方法执行的效果,具体可以看下手册控制器章节。
kissgxd 发表于 2014-3-4 15:27 static/image/common/back.gif
我的C里经常exit啊
莫非父类里不能exit
确实不可以 exit,会有很多副作用,把 exit 换成 return 会比较合适。
$this->load->view('Public/Info');
改为:
echo $this->load->view('Public/Info',Null,True);
这样就可以用exit了。 Hex 发表于 2014-3-4 15:28 static/image/common/back.gif
可以试试 _remap 方法来实现中断 index 方法执行的效果,具体可以看下手册控制器章节。
...
正在尝试
李三 发表于 2014-3-4 15:47 static/image/common/back.gif
$this->load->view('Public/Info');
改为:
echo $this->load->view('Public/Info',Null,True);
错误不对 谢谢了
页:
[1]
2