简体   繁体   English

在CodeIgniter中设置完整的网站页面

[英]Setting up a full site page in CodeIgniter

I am just starting with CodeIgniter, but I can't quite figure how to sort out my views. 我只是从CodeIgniter开始,但是我不太清楚如何整理我的观点。

I've made a sample layout explaining my problem, and is attached to this post. 我已经制作了一个示例布局来解释我的问题,并已附在这篇文章上。

I have a menu box , a user-system box and a content box. 我有一个菜单框 ,一个用户系统框和一个内容框。

In procedural PHP I would have a page called index.php with a parameter from GET , including the content . 在过程PHP中,我将创建一个名为index.php的页面,其中包含GET的参数,包括内容 The user-system would just be included in the index.php file inside the box, and so would the menu . 用户系统将仅包含在框内的index.php文件中, 菜单也将包含在内。

How can I do this in a proper way using MVC and CodeIgniter? 如何使用MVC和CodeIgniter以正确的方式执行此操作?

在此处输入图片说明

Try Most Simple Template Library for CodeIgniter . 试用CodeIgniter的最简单模板库 It allows you to do what you would do in your php example. 它允许您做您将在php示例中做的事情。 Create a "main" view and channel your content to it using your controller(s). 创建一个“主”视图,然后使用您的控制器将您的内容引导至该视图。 You can create "subthemes" for body, content, sidebars etc. 您可以为正文,内容,侧边栏等创建“子主题”。

Hope you have configured codeigniter on your machine. 希望您已在计算机上配置了codeigniter。

now create one file in controller folder for example : D:\\wamp\\www\\demoProject\\application\\controllers\\homePage.php 现在在控制器文件夹中创建一个文件,例如:D:\\ wamp \\ www \\ demoProject \\ application \\ controllers \\ homePage.php

add following code in homePage controller 在homePage控制器中添加以下代码

    <?php

    class HomePage extends CI_Controller {

        var $controller = "homePage";        
        var $viewContent = array();              

        function list_homePage() {   

// Load view pages // Load header view page //加载视图页面//加载标题视图页面

            $this->load->view('xome/header');

// Load main view page //加载主视图页面

            $this->load->view('xome/list_' . $this->controller, 
            $this->viewContent);

// Load footer view page //加载页脚视图页面

            $this->load->view('xome/footer');
        }
}
?>

after that create one file in view folder for example : D:\\wamp\\www\\demoProject\\application\\views\\list_homePage.php 之后,在视图文件夹中创建一个文件,例如:D:\\ wamp \\ www \\ demoProject \\ application \\ views \\ list_homePage.php

put your html code in view file. 将您的html代码放入视图文件中。

Hope this will help you... :) 希望这个能对您有所帮助... :)

For menu I would create a model like this: 对于菜单,我将创建一个这样的模型:

class mMenu extends CI_Model{

 function mMenu(){
  parent::__construct();
 }

 function home(){
  $menu = array(
    'main_menu' => '<ul>
                      <li>Menu Link 1</li>
                      <li>Menu Link 2</li>
                      <li>Menu Link 3</li>
                    </ul>'
  );
  return $menu;
 }
}

In controller, say home: 在控制器中,说回家:

function home(){
 $this->load->model('mMenu');
 $options['menu'] = $this->mMenu->home();

 $this->load->view('home_view', $options);
}

In the view file, wherever I need the menu to load: 在视图文件中,需要加载菜单的位置:

echo $menu['main_menu'];

You should do something similar to control the state of the user and return the form if the user is not logged in and anything else if the user is logged in. 您应该执行类似的操作来控制用户的状态,如果用户未登录,则返回表格,如果用户已登录,则执行其他操作。

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

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