代码点火器 :: 包括?
我是代码点火器的新手,仍在学习最佳实践。
在我的网站中,我有两个菜单,
一个用于登录的用户,
一个用于注销的用户。
我将它们放在视图文件夹中的两个文件中。
我的问题是:
我应该如何将这些包括在内?
我最好的猜测是
在控制器调用中
if($loggedin)
$menu = $this->load->view('loggedin', true);
else
$menu = $this->load->view('loggedout', true);
$this->load->view('main', array('menu' => $menu));
,所以基本上将正确的菜单代码传递到视图中并回显出来。
有更好的方法吗?
I am new to code igniter and am still learning the best practices.
In my site I have two menus,
One for users who are logged in.
One for users who are logged out.
I have these in two files in the views folder.
My question is:
How should I go about including these?
my best guess is to
in the controller call
if($loggedin)
$menu = $this->load->view('loggedin', true);
else
$menu = $this->load->view('loggedout', true);
$this->load->view('main', array('menu' => $menu));
So basically pass the correct menu code into the view and echo that out.
Is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以打破严格的 MVC 并在你的观点中拥有类似的东西:
你的观点:
记住 MVC 是一个概念,它不是一成不变的。
you can break strict MVC and have something like this in your view:
your view:
remember MVC is a concept, it isn't set in stone.
您可以在函数中加载任意数量的视图。例如:
使其变得更清洁,但效率节省可能可以忽略不计。
You can load as many views as you like in the function. So for example:
Makes it a little cleaner but probably negligible efficiency savings.
我建议你使用插件。
将其放入插件中
I would suggest you to use plugins.
put this in to plugin