代码点火器-您将如何构建此网站? [英] Code Igniter - how would you structure this site?

查看:51
本文介绍了代码点火器-您将如何构建此网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在代码点火器中建立我的第一个站点,这是一个相当基本的站点:

I'm going to do my first site in code ignitor, a fairly basic site like this:


home
登录/注册

home login / register

members area
protected page 1 
protected page 2
protected page 3

general info section
page 1
page 2
page 3 (dynamic table of reports)

about section
page 1
page 2

blog section
listing
article page


我经历了一些基本的练习,并且阅读了一些文档,但是仍然不确定什么是构造此方法的最佳方法。拥有CI经验的人可以给我看看他们如何做事的例子吗?

I've gone through a couple of basic tuts and have read some of the documentation but still feel unsure on what would be the best way to structure this. Could anyone that is experienced with CI show me an example of how they' do it?

一些特定的问题是:


  1. 带有导航面板的标题在所有页面上都相同。通常,我会编写代码,将其包含在if / else中,以显示突出显示的当前部分。我想我只是将其保留为包含(视图)并通过控制器首先加载它,还是将其包含在每个视图中?

  1. header with nav panel will be the same on all pages. normally i'd code that as an include with if/else to show highlighted current section. I guess I'd just keep this as an include (view) and either load it first via the controller or include it in every view?

我会设想有一个名为用户的模型来处理登录和注册,一个名为博客的模型和一个名为报告的模型。听起来对吗?

I'd envisage having a model called 'user' which will handle the login and registration, a model called 'blog' and a model called 'reports'. Does that sound right?

对于诸如此类的静态部分,我想没有模型,而我只是为每个静态页面提供了一个带有功能的控制器?即about.php与page1(),page2()及其所做的就是加载静态视图吗?

for static sections like about, I guess there'd be no model and i'd just have a controller with a function for each static page? i.e. about.php with page1(), page2() and all they do is load static views?


推荐答案

您应该使用CI库来处理用户注册和每页授权。
这是一个有关如何操作的非常简单的示例。请记住,CI使用 MVC模式

You should use an CI library to handle your user registration and per page authorisation. Here's a very simple example on how you could do it. Keep in mind that CI uses the MVC pattern

    class Reports extends CI_Controller {

        public function __construct() {
           parent::__construct();
           // load database if needed
           // load a model if needed

        }

        public function page() {
            //get the page requested
            $page_id = $this->uri->segments(2);
            // based on the page_id do something.

            $data['somedata'] = 'About us data here';

            // this is an actual file loaded from the template view
            $data['maincontent'] = 'my_page';
            $this->load->view('template',$data);
        }

    }

    class About extends CI_Controller {

        public function __construct() {
           parent::__construct();
           // load database if needed for this page
        }

        public function page() {
            // same here
            //get the page requested
            $page_id = $this->uri->segments(2);
            // based on the page_id do something.

            $data['somedata'] = 'About us data here';

            // this is an actual file loaded from the template view
            $data['main_content'] = 'my_about_page';
            $this->load->view('template',$data);
        }
    }

    $this->load->view('template/header');
    $this->load->view('template/nav');
    $this->load->view($main_content);
    $this->load->view('template/footer');

这篇关于代码点火器-您将如何构建此网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆