您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
扩展CI的控制器
发布时间:2020-01-23 12:19:08编辑:雪饮阅读()
在application/core中建立My_Controller.php
<?php
class My_Controller extends CI_Controller{
public function __construct()
{
parent::__construct();
echo "dmj";
}
}
然后随便找一个控制器就可以继承上面的控制器了
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends My_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$res=$this->db->where("name","dmj")->get("blog_user");
$res=$this->db->where(["name"=>"dmj"])->get("blog_user");
$res=$this->db->where(["name"=>"dmj","id >"=>2])->get("blog_user");
var_dump($res->result());
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
这就是ci扩展控制器的方法,当然控制器前缀可以不固定为“My”默认为“My”,在配置文件application/config/config.php中:
$config['subclass_prefix'] = 'MY_';
关键字词:ci,控制器,扩展
上一篇:CI中的AR(连惯操作)
下一篇:CI中的模型model