0

CI_Controller を上書きして、各コントローラーに固有のユーザー チェックを実行できるようにしました。

これはすべて正常に動作しますが、ここで出力を上書きしただけです

class Guest_Controller extends CI_Controller
{  
    public function __construct() 
    {
        parent::__construct();
    }

    public function _output($content)
    {
        // Load the base template with output content available as $content
        $data['content'] = &$content;       
        echo($this->load->view('templates/html_guest', $data, true));
    }
}

class Homepage extends Guest_Controller {
    public function __contruct()
    {
    }

    public function index()
    {
        $data = array(
            'title' => 'Homagepage',
            'page_title' => 'Homepage',
            'body_classes' => 'home'
        );
        $this->parser->parse('homepage', $data);
    }
}

$dataが持っていることがわかりますbody_classes。これを使用して、各ページに独自のニーズに基づいて個別のクラスを与えることができます。さて、body_classes私のにデフォルトを追加する最良の方法は何でしょうGuest_Controllerか?

がhomebody_classのみの場合、デフォルトのものをいくつか追加するにはどうすればよいですか?

編集:だから私はまだいくつかのデフォルトのものを持っている間にボディクラスを簡単に追加する方法を探しています.

4

1 に答える 1

1
class Guest_Controller extends CI_Controller
{  
    public function __construct() 
    {
        parent::__construct();
    }

    public function _output($content)
    {
        // Load the base template with output content available as $content
        $data['content'] = &$content;       
        echo($this->load->view('templates/html_guest', $data, true));
    }

    //specify default values with $page_info
    protected function get_page_info($page_info)
    {
         $data = array(
            'title' => 'default',
            'page_title' => 'default',
            'body_classes' => 'default'
         );

         foreach ($page_info as $key => $value) 
             $data[$key] = $value;    

         return $data;        
    } 

}

class Homepage extends Guest_Controller {
    public function __contruct()
    {
    }

    public function index()
    {
        $data = array(
            'title' => 'Homagepage',
            'page_title' => 'Homepage',
        );
        $this->parser->parse('homepage', $this->get_page_info($data));
    }
}
于 2012-12-19T08:37:54.983 に答える