close

2.1版在core下建立MY_Controller.php檔案

內容為:

/*-------------------------------------*/

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class FUN_Controller extends CI_Controller{

    public $site = array(
                "name" => "網站名稱",
                "tag" => "標籤"
    
            );
    public function __construct()
    {
        parent::__construct();
    }
 
    function FUN_Controller ()  {
        parent::Controller();
    }

}

/*-------------------------------------*/

 

Controller繼承

/*-------------------------------------*/

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Front extends FUN_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()
    {
        echo $this->site['name']; //呼叫變數(全域)
        $this->load->view('Front',$data);
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/Front.php */

 

/*-------------------------------------*/

全站熱搜
創作者介紹
創作者 incode 的頭像
incode

程式筆記本

incode 發表在 痞客邦 留言(0) 人氣()