【发布时间】:2015-02-23 20:06:08
【问题描述】:
我正在使用基于地址的控件和带有 index.php?site=filename 的 GET 方法对 PHP 进行编码。然后我将现有的 filename.php 包含在内容 div 中。那很简单,但很有效。我也有通知 div 我在其中包含来自数据库的数据的文件
我正在尝试在 CodeIgniter 中获得类似的结果
html
head
/head
body
div notification bar (always on top like Material)
div menu (slide from left also like Material)
div content (depended on controller and loaded view)
div footer (only /body /html)
/body
/html
通过
public function __construct()
{
parent::__construct();
$this -> load -> view('notification ');
$this -> load -> view('menu ');
}
我想将数据从模型发送到通知视图,但我不能在构造函数中执行此操作。我也不想在每个控制器的方法中加载相同的视图。我该怎么做?我不希望有现成的解决方案,但有一些想法,也许是伪代码?
或者也许这只是这样的一种解决方案?在每种方法中加载所有需要的视图?真的吗?
class news extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this -> load -> view('header');
}
public function index()
{
[...]//data from model
$this -> load -> view('notification',$Data);
$this -> load -> view('menu',$Permission);
$this -> load -> view('news',$Content);
}
[...]
【问题讨论】:
-
为什么不简单地创建一个包含视图的视图(有点像子视图)?做起来不难,见stackoverflow.com/questions/9402924/…
-
好的,谢谢,我会这样做,但它不能解决我在通知中的数据问题。一些通知将处于非活动状态,那么它们的设置如何?或者我可以使用 mysql 查询在视图代码中设置它,但这违反 MWC 规则,不是吗?你觉得怎么样?
标签: php codeigniter get construct