php继承controller,CI3如何使用controller继承-ITKEE社交系统-ITKEE社区-轻量级社区-thinkphp开发社区-HTML模板资源分享-thinkphp技术交流-thi...

ITKEE社区V3.0.1版本更新,补丁包下载了解详情 , 获取ITKEE社区版本,快速授权了解详情

这两天看了下CI3,想使用controller继承,后来才发现CI的继承是另有玄机,这里做个笔记。

1、检查application\config\config.php文件$config['subclass_prefix'] = 'MY_';

值为My_,那么你的controller需要以这个开头

2、在application\core文件夹下面新建My_Controller.php文件<?phpdefined ('BASEPATH') OR exit('No direct script access allowed');/**

*My_Controller

**/class My_Controller extends CI_Controller{public function __construct(){parent::__construct();

}

}?>

3、在你的controllers中使用它<?phpdefined ('BASEPATH') OR exit('No direct script access allowed');class User extends My_Controller{

public function __construct(){parent::__construct();$this->load->library('theme');

}

}

?>

备注:如果需要扩展多个继承,那么需要在application\core\My_Controller.php文件中书写多个controller<?php

defined('BASEPATH') OR exit('No direct script access allowed');/**

*基础controller

**/class My_Controller extends CI_Controller{public function __construct(){parent::__construct();

}

}class BaseController extends My_Controller{public function __construct(){parent::__construct();

}

}class AdminController extends My_Controller{public function __construct(){parent::__construct();

}

}?>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值