简体   繁体   English

需要帮助以在Codeigniter中配置CSS模板

[英]Need help to configure CSS template in codeigniter


I am having trouble to configure only css template in codeigniter. 我在codeigniter中仅配置css模板时遇到麻烦。 eg: i am beginner in codeigniter. 例如:我是Codeigniter的初学者。 any one can tell me that how can i configure it or any tutorial. 任何人都可以告诉我如何配置它或任何教程。 hope you understand my bad English.. 希望你能理解我的英语不好。

here is my code 这是我的代码

in view page home.php 在查看页面home.php

<?php $this->load->view('header_final');?>



     <div id="page">
        <div id="page-bgtop">
            <div id="page-bgbtm">
                <div id="content">
                    <div class="post">
                        <h2 class="title"><a href="#">Home</a></h2><br>

                        <div class="entry">
                            <p><img src="<?=site_url();?>images/img08.jpg" width="538" height="200" alt="" /></p>
                            <p>Sylhet Engineering College (SEC), established in the year 2007 under the School of Applied Science and Technology, Shahjalal University of Science and Technology is best of its kind with a motto to produce the best in class engineers for the 21st century in Bangladesh. There are five universities of Engineering and Technology and some private universities in the country for providing engineering education at B.Sc level which is not sufficient to meet the requirement of today's fast paced engineering sector of Bangladesh. As a divisional city of Bangladesh, Sylhet had no engineering institute. So the Government of Peoples Republic of Bangladesh has established Sylhet Engineering College with a vision to expand the engineering education of Bangladesh as an engineering faculty section of Shahjalal University of Science and Technology.</p>

                        </div>
                    </div>



                    <div class="post">


                    </div>
                    <div style="clear: both;">&nbsp;</div>
                </div>
                <!-- end #content -->


<?php $this->load->view('footer_final');?>


In controller page home.php 在控制器页面home.php

<?php

class Home extends Controller {

    function Home()
    {
        parent::Controller();   

    }

    function index()
    {

        $this->load->view('home');


    }
}

Hints: 提示:

header_final.php and footer-final.php header_final.phpfooter-final.php

CodeIgniter allows you to load multiple views at the same time. CodeIgniter允许您同时加载多个视图。 You want to leave your view loads in your controller. 您想将视图负载保留在控制器中。 So what you want to do is load the header view in the controller, then load the actual view you want rendered and then load the footer view. 因此,您要做的是在控制器中加载页眉视图,然后加载要渲染的实际视图,然后加载页脚视图。 When done it will look something like this: 完成后,它将类似于以下内容:

function index(){
    $this->load->view('header_final');
    $this->load->view('home');
    $this->load->view('footer_final');
}

Then remove all the view loads from your home.php view. 然后从home.php视图中删除所有视图负载。

The proper way to do this is to use the controller to manipulate your views. 正确的方法是使用控制器来操纵视图。 Your default controller is specified in the "system/app/config/routes.php" file. 您的默认控制器在“ system / app / config / routes.php”文件中指定。 The parameters "default_controller" tells the application which controller you want to use by default. 参数“ default_controller”告诉应用程序默认情况下要使用哪个控制器。

As Carl said, once you have placed all the line of codes you need to load the necessary views, you can point the default_controller to this controller. 正如Carl所说,一旦放置了所有代码行,就需要加载必要的视图,则可以将default_controller指向该控制器。 Note that the function index is the default function used by a controller. 请注意,功能索引是控制器使用的默认功能。

Once you'll go on, you may need to build a custom controller since all of your page are will need this header and footer. 一旦继续,您可能需要构建自定义控制器,因为所有页面都需要此页眉和页脚。 I did it by addind a file under "system/app/core/MY_Controller.php" (Code igniter 2.X, not the same for different version) and I extend this controller instead. 我通过在“ system / app / core / MY_Controller.php”下添加一个文件来做到这一点(代码点火器2.X,不同版本不相同),我改为扩展了该控制器。 The code within this controller looks like this : 该控制器中的代码如下所示:

    <?php

 class MY_Controller extends CI_Controller {

    function __construct() {
        parent::__construct();
    }
    public function loadHeader($data = Array(),$customHeader = 'parts/header'){
        $this->load->view($customHeader,$data);
    }
    public function loadFooter($data = Array(),$customFooter = 'parts/footer'){
        $this->load->view($customFooter,$data);
    }
    public function loadSidebar($data = Array(),$customSidebar = 'parts/sidebar'){
        $this->load->view($customSidebar,$data);
    }
}

Then from my controller I do something like this : 然后从我的控制器执行以下操作:

    <?php

class Articles extends MY_Controller {
    public function  __construct() {
        parent::__construct();
    }
    /**
     * Controller for all news.
     * will be used as home controller.
     */
    public function index() {
        //Needed helper

        //End helper
        $data = Array();
        //Fill the array for the header part
        $data["header"] = Array();
        $data["header"]["title"] = "Articles shelf";
        $data["header"]["logo"] = "David Francoeur";
        $data["header"]["slogan"] = "just a blog about me and knowledge...";
        $this->loadHeader($data["header"]);// I would add a second parameter for a custom header.
        //Fill the array for the rest of the pages
        $data["main"] = Array();
        $this->load->model('Article');
        $data["main"]["query"] = $this->Article->get_last_ten_entries();
        $this->load->view('article', $data["main"]);
        //Fill the array for the right sidebar
        $data["sidebar"] = Array();
        $this->loadSidebar($data["sidebar"]);
        //Fill the array for data concerning the footer
        $data["footer"] = Array();
        $this->loadFooter($data["footer"]);//I would add a second parameter for a custom footer.
    }

}

You could also use a single function in your custom controller if you don't need custom header or footer something like : 如果不需要自定义页眉或页脚,也可以在自定义控制器中使用单个函数:

<?php

class MY_Controller extends CI_Controller { 类MY_Controller扩展了CI_Controller {

function __construct() {
    parent::__construct();
}
public function loadView($data = Array(),$view){
    $this->load->view("header_final");
    $this->load->view($view,$data);
    $this->load->view("footer-final");
}
}

It's up to you! 由你决定!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM