开发者

Controller specific html in default.ctp in cakephp

The question is simple and straight but 开发者_开发百科I can't find an answer for it. is it possible to put a control dependent html inside a default.ctp layout? I mean for example if the layout is being compiled for the user controller add an html element to it and if it is being compiled for foo controller another one to be included? these elements are and have to be defined outside the $content_for_layout part and cannot be included inside that.

I have to mention that I'm using cakephp 1.3


Just check the controller set in the $params array.

For example, you could put this in your layout:

<?php if ($this->params['controller'] == 'users'): ?>
    Your controller dependent HTML here
<?php endif; ?>

There are many other ways to approach this but the main point is that you can find out what controller is producing the view by checking the $this->params array from within a view or layout file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜