Is there anything like MasterPages on CodeIgniter Framework?

前端 未结 4 664
無奈伤痛
無奈伤痛 2021-01-04 11:40

I am new to Code Igniter and I wish to know if there is anything that works like MasterPages do on .NET.

Also i was wondering where should i keep my public files, li

4条回答
  •  灰色年华
    2021-01-04 12:21

    Master views aren't built into the framework. To get a similar effect you can load the subview and pass that to the master view.

    Controller :

    class Items extends Controller
    {
        function show($id)
        {
            $item = $this->item_model->get_item($id);
    
            // Load the subview
            $content = $this->load->view('item/show', array('item' => $item), true);
    
            // Pass to the master view
            $this->load->view('master_view', array('content' => $content));
        }
    }
    

    Master view :

    
    

    To answer your other question, I keep all Javascript scripts and CSS in directories in the root of my project.

提交回复
热议问题