用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2783|回复: 12
收起左侧

[版本 2.x] 帮忙帮下 流程问题 不知道要怎么处理 麻烦各位

[复制链接]
发表于 2014-3-4 15:15:43 | 显示全部楼层 |阅读模式
本帖最后由 星辰大海 于 2014-3-4 15:22 编辑

My_Controller.php
PHP复制代码
 
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Hantech_Controller extends CI_Controller {
       
        private $msg = array();
 
        public function __construct() {
                parent::__construct();
        }
 
        /**
         * 输出信息类型
         * @return [type] [description]
         */

        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 [type] [description]
         */

        public function checkAuthInfo() {
 
                $this->load->library('auth');
                if ( !$this->auth->checkAuthInfo() ) {
                     $this->msg = $this->auth->getErrorInfo();
                     $this->outPageInfo();
                }
        }
}
 
 
复制代码


actionAction.php
PHP复制代码
 
<?php  if ( ! 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方法




 楼主| 发表于 2014-3-4 16:20:59 | 显示全部楼层
Hex 发表于 2014-3-4 15:23
控制器中不能使用 exit,必须使用 return,因为 CI 要在你的函数结束后做很多其他事情。

可以试试 _remap  ...

解决了  谢谢 _remap

PHP复制代码
 
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 [type] [description]
         */

        public function checkAuthInfo() {
 
                $this->load->library('auth');
                if ( !$this->auth->checkAuthInfo() ) {
                     $this->msg = $this->auth->getErrorInfo();
                     $this->flag = false;
                }
        }
}
 
复制代码


 楼主| 发表于 2014-3-4 15:17:25 | 显示全部楼层
本帖最后由 星辰大海 于 2014-3-4 15:23 编辑

帮帮忙 谢谢
发表于 2014-3-4 15:23:01 | 显示全部楼层
控制器中不能使用 exit,必须使用 return,因为 CI 要在你的函数结束后做很多其他事情。

可以试试 _remap 方法来实现中断 index 方法执行的效果,具体可以看下手册控制器章节。
 楼主| 发表于 2014-3-4 15:26:57 | 显示全部楼层
Hex 发表于 2014-3-4 15:23
控制器中不能使用 exit,必须使用 return,因为 CI 要在你的函数结束后做很多其他事情。

另外,你可能需要 ...

如果每个都去添加判断 就太麻烦了 还是感谢

发表于 2014-3-4 15:27:51 | 显示全部楼层
我的C里经常exit啊
莫非父类里不能exit
发表于 2014-3-4 15:28:04 | 显示全部楼层
星辰大海 发表于 2014-3-4 15:26
如果每个都去添加判断 就太麻烦了 还是感谢

可以试试 _remap 方法来实现中断 index 方法执行的效果,具体可以看下手册控制器章节。
发表于 2014-3-4 15:28:57 | 显示全部楼层
kissgxd 发表于 2014-3-4 15:27
我的C里经常exit啊
莫非父类里不能exit

确实不可以 exit,会有很多副作用,把 exit 换成 return 会比较合适。

发表于 2014-3-4 15:47:20 | 显示全部楼层
$this->load->view('Public/Info');
改为:
echo $this->load->view('Public/Info',Null,True);
这样就可以用exit了。
 楼主| 发表于 2014-3-4 15:54:40 | 显示全部楼层
Hex 发表于 2014-3-4 15:28
可以试试 _remap 方法来实现中断 index 方法执行的效果,具体可以看下手册控制器章节。
...

正在尝试

 楼主| 发表于 2014-3-4 16:05:05 | 显示全部楼层
李三 发表于 2014-3-4 15:47
$this->load->view('Public/Info');
改为:
echo $this->load->view('Public/Info',Null,True);

错误  不对 谢谢了

本版积分规则