我想在这些日子学习codeigniter,并且我正在努力根据路由理解视图,控制器和模型的结构以保持安全性。CodeIgniter:从子文件夹访问视图
那么,我们应该如何构建我们的视图,控制器和管理后端和用户后端模型,我的意思是文件夹,子文件夹和路由?
首先我想何况我怎么把我的文件,以便: 我的路线:
$route['default_controller'] = 'site/home';
$route['home'] = 'site/home';
所以这里默认的控制器Site.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$data['body']='site/home';
$this->load->view('includes/template',$data);
}
public function home(){
$data['body']='site/home';
$this->load->view('includes/template',$data);
}
public function AnotherMethod(){
$data['body']='site/AnotherPage';
$this->load->view('includes/template',$data);
}
而我的观点是模板(views/includes/template.php):
<?php
//load head
$this->load->view('includes/header');
//load body
$this->load->view($body);
//load footer
$this->load->view('includes/footer');
?>
所以,如果我把这样的东西,我有问题从子文件夹访问视图。作为一个例子,
directory : views/site/userbackend/index.php
or views/site/adminbackend/index.php
,也有根据管理后台和用户后端控制器和模型子文件夹。
我将如何访问它们?
我在这里只是想显示什么样的我有.. 所以现在所有的问题的答案可以,如果你只告诉我到场景的专家怎么办和结构部件有哪些亟待解决的问题是最佳实践。
我知道我已经使这个问题在许多事情上很复杂,我很抱歉,如果你想让我对一个主题更清楚,告诉我,我会更新我的问题。
需要帮助的人在这里。 在此先感谢!
http://developers.ph/codeigniter/hmvc-pattern-codeigniter-php-framework/这可能有帮助 –
@MalikMudassar感谢您的链接,我会研究它。 –