Cakephp 每个控制器有多个视图
我有一个具有 3 个功能的控制器。我希望根据用户是来自移动设备、网站还是 Facebook,在每个功能中显示 3 种不同的视图和布局。我已经传递了用户来自的地方。
我不确定如何为每个视图显示特定的视图和布局。这是我开始更改布局的一些代码。我的视图位于名为 res 的文件夹中。
function availability() {
if ($_REQUEST['from'] == 'facebook') {
$this->layout = 'facebook';
print_r ('face');
}elseif ($_REQUEST['from'] == 'website'){
$this->layout = 'website';
print_r ('web');
}elseif ($_REQUEST['from'] == 'mobile'){
$this->layout = 'mobile';
print_r ('mobile');
};
}
I have a controller which has 3 functions. I wish to show 3 different views and layouts in each function depending on whether the user comes from mobile, website or facebook. I am passing in already where the user is coming from.
I am unsure how I would then show a particular view and layout for each. Here is some code that I started to do to change the layout. I have the views in a folder called res.
function availability() {
if ($_REQUEST['from'] == 'facebook') {
$this->layout = 'facebook';
print_r ('face');
}elseif ($_REQUEST['from'] == 'website'){
$this->layout = 'website';
print_r ('web');
}elseif ($_REQUEST['from'] == 'mobile'){
$this->layout = 'mobile';
print_r ('mobile');
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
$this->render()
更改视图。您还可以将不同布局的所有视图放入各自的文件夹中,并设置视图路径,这样您就不必在每个函数中手动选择视图:
现在,Facebook 布局的操作“可用性”视图是从 <代码>facebook/availability.ctp。
Use
$this->render()
to change the view.You could also put all the views for different layouts to their own folders and set the viewpath so that you don't have to choose the views manually in each function:
Now the view for action "availability" for the Facebook layout is fetched from
facebook/availability.ctp
.