在codeigniter中分离模型文件夹,视图文件夹和控制器文件夹 [英] separating Model folder, view folder and controller folder in codeigniter
问题描述
我可以将codeigniter的MVC结构的模型和视图文件夹放置到不同的位置,而不考虑常规路径
/ views
application / models
到某个其他位置,让说
abc / views
pqr / models
$ b b
在项目文件夹之外。
如果可能的话,我将如何实现它。
提前谢谢。
没有功能可以自定义CodeIgniter当前稳定版本中的 但您可以在典型的 文件的路径是相对的。因此,您可以使用 例如,如果 查看下面的示例: 模型: strong> strong> 这是示例文件夹结构: strong>侧键:确保直接访问 can i place the model and view folders of the MVC structure of codeigniter to different location irrespective to the regular path to some other location, lets say outside the project folder.
if possible then how can i achieve it. thank you in advance There's no feature to customize the But you can load your files outside of the typical The path to the file is relative. So you can use For example, If the Take a look at the example below: Model: Controller: View: Here is the sample folder structure:
As a Side-note: Make sure direct accessing to the 这篇关于在codeigniter中分离模型文件夹,视图文件夹和控制器文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!模型
和视图
路径(在CI 3.x中,您可以更改视图
路径以及应用程序
和
视图之外加载您的文件$> c $ c>和
模型
文件夹。
../
在路径中移动一个 UP 级别。
abc
文件夹放置在应用程序
附近,则应使用 ../
class Model_name extends CI_Model {
public function baz($ value ='')
{
return $ value;
}
}
class Foo extends CI_Controller {
public function bar()
{
$ this-> load-> model('../../ pqr / models / model_name');
$ data ['var'] = $ this-> model_name-> baz('Yes It Works!');
$ this-> load-> view('../../ abc / views / view_name',$ data);
}
}
<?php echo $ var; >
应用程序
system
pqr
/ models
/model_name.php
abc
/ views
/view_name.php
pqr
或 abc
目录受到限制。在其中添加 .htaccess
文件,其内容为从全部
中拒绝。 application/views
application/models
abc/views
pqr/models
models
and views
path in CodeIgniter current stable versions (while in CI 3.x you can change the view
path as well as application
and system
).views
and models
folders.../
to go one UP level in path.abc
folder is placed near application
, you should use ../../abc
to reach to that folder.class Model_name extends CI_Model {
public function baz($value='')
{
return $value;
}
}
class Foo extends CI_Controller {
public function bar()
{
$this->load->model('../../pqr/models/model_name');
$data['var'] = $this->model_name->baz('Yes It Works!');
$this->load->view('../../abc/views/view_name', $data);
}
}
<?php echo $var; ?>
application
system
pqr
/models
/model_name.php
abc
/views
/view_name.php
pqr
or abc
directories is restricted. add a .htaccess
file inside them with the content of Deny from all
.