【ci框架】扩展系统的核心类

首先你系统扩展类是放在application/core下面的,本来系统核心类是CI_Controller,所以你不能以CI_开头了,你需要打开 application/config/config.php 修改 $config['subclass_prefix'] = 'MY_'; 为你的前缀!

一些公共的模块就可以卸载自己的核心类里面了!

这几天读了Dilicms(轻量级的后台架构),比如说他的后台扩展类是这样的:



  
  
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. abstract class Admin_Controller extends CI_Controller
  3. {
  4. /**
  5. * _admin
  6. * 保存当前登录用户的信息
  7. *
  8. * @var object
  9. * @access public
  10. **/
  11. public $_admin = NULL;
  12.  
  13. /**
  14. * 构造函数
  15. *
  16. * @access public
  17. * @return void
  18. */
  19. public function __construct()
  20. {
  21. parent::__construct();
  22. $this->load->library('session');
  23. $this->settings->load('backend');
  24. $this->load->switch_theme(setting('backend_theme'));
  25. $this->_check_login();
  26. $this->load->library('acl');
  27. $this->load->library('plugin_manager');
  28. }
  29. // ------------------------------------------------------------------------
  30.  
  31. /**
  32. * 检查用户是否登录
  33. *
  34. * @access protected
  35. * @return void
  36. */
  37. protected function _check_login()
  38. {
  39. if ( ! $this->session->userdata('uid'))
  40. {
  41. redirect(setting('backend_access_point') . '/login');
  42. }
  43. else
  44. {
  45. $this->_admin = $this->user_mdl->get_full_user_by_username($this->session->userdata('uid'), 'uid');
  46. if ($this->_admin->status != 1)
  47. {
  48. $this->session->set_flashdata('error', "此帐号已被冻结,请联系管理员!");
  49. redirect(setting('backend_access_point') . '/login');
  50. }
  51. }
  52. }
  53. // ------------------------------------------------------------------------
  54.  
  55. /**
  56. * 加载视图
  57. *
  58. * @access protected
  59. * @param string
  60. * @param array
  61. * @return void
  62. */
  63. protected function _template($template, $data = array())
  64. {
  65. $data['tpl'] = $template;
  66. $this->load->view('sys_entry', $data);
  67. }
  68. // ------------------------------------------------------------------------
  69.  
  70. /**
  71. * 检查权限
  72. *
  73. * @access protected
  74. * @param string
  75. * @return void
  76. */
  77. protected function _check_permit($action = '', $folder = '')
  78. {
  79. if ( ! $this->acl->permit($action, $folder))
  80. {
  81. $this->_message('对不起,你没有访问这里的权限!', '', FALSE);
  82. }
  83. }
  84. // ------------------------------------------------------------------------
  85.  
  86. /**
  87. * 信息提示
  88. *
  89. * @access public
  90. * @param string
  91. * @param string
  92. * @param bool
  93. * @param string
  94. * @return void
  95. */
  96. public function _message($msg, $goto = '', $auto = TRUE, $fix = '')
  97. {
  98. if($goto == '')
  99. {
  100. $goto = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : site_url();
  101. }
  102. else
  103. {
  104. $goto = strpos($goto, 'http') !== false ? $goto : backend_url($goto);
  105. }
  106. $goto .= $fix;
  107. $this->_template('sys_message', array('msg' => $msg, 'goto' => $goto, 'auto' => $auto));
  108. echo $this->output->get_output();
  109. exit();
  110. }
  111. }
  112.  

它就把一些公共信息入验证,登陆,跳转放在Admin_Controller里面,于是我在写前台的时候也是这样操作,扩展了Font_Controller:



  
  
  1. abstract class Font_Controller extends CI_Controller{
  2. public function __construct() {
  3. parent::__construct();
  4. }
  5.  
  6. //前台加载视图方法
  7. public function _template($template, $data = array()){
  8. $data['nav'] = $this->get_nav();
  9. $data['tpl'] = $template;
  10. $this->load->view('default',$data);
  11. }
  12. //公共导航信息
  13. public function get_nav(){
  14. }
  15. //公共友情链接信息
  16. public function get_friendlink(){
  17. }
  18. }

提示,一些经常用到得工具和函数可以放在helper中!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值