Codeigniter 通过控制器包含 .php 文件
有没有办法通过控制器动态包含文件,就像 include('path_to_file') 一样。
我得到的唯一建议是定义它
$data = array('var'=>'path1','var2'=>'path2');
并通过加载视图传递它,但这不会加载文件,所以我基本上回到了开始的地方。
Is there a way to dynamically include files through the controller, just as you would do include('path_to_file').
The only advice I've gotten was to define it like
$data = array('var'=>'path1','var2'=>'path2');
and pass it through the load view, but this doesn't load the files, so I'm basically back where I started.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就像Repox所说,你应该遵循MVC结构。一般来说,如果您计划包含类(功能),请使用模型;如果您想包含演示文稿 (html),请使用视图。所有这一切都应该由控制器完成。例如:
如果确实需要,还可以从视图中调用模型和视图。
希望这能澄清一点。
Like Repox said, you should follow the MVC structure. Generally, if you plan to include classes (functionality), use models; if you want to include presentation (html), use views. And all this should be done from a controller. For example:
If you really need it, you can also call models and views from a view.
Hope this clears it up a bit.
简短的回答 - 不。
更详细的答案是为您提供有关如何正确使用 MVC 的详细信息。
将您不想包含到模型、视图和控制器中的文件拆分是正确的做法。这就是 CI 中的“动态包含文件的方式”。
Short answer - no.
A more detailed answer would be providing you with details on how to use the MVC correctly.
Splitting up the file you wan't to include into models, views and controllers would be the correct thing to do. That is 'the dynamic way to include files' in CI.