开发者

Pass data to default.ctp (layout file) from random controller in CakePHP

开发者 https://www.devze.com 2023-02-07 15:34 出处:网络
I am simply trying to pass data from my controller to my default layout file: users_controller $this->set(\'fish\', \'trout\');

I am simply trying to pass data from my controller to my default layout file:

users_controller

$this->set('fish', 'trout');

default.ctp (layout file)

echo "You caught a " . $fish. " from the river.";

What I am trying to achieve is: echo $group['Group']['name']; in the default layout file, but the above was 开发者_运维知识库my first attempt to understand how the relationship actually works.

Thanks for any advise on this : )


anything that you set to the view is available in the layout.


If you set anything in the default.ctp, it will show in the layout just like you would do in a view. There's no difference.

You might not be seeing anything because you have set debug to 0 and you have an error. Try making it 2 and check it out.


As Thorpe says, you need debug set to non-zero.

Check (and change) in app/core.php (search the file for debug and you'll see the information you need).

If you're not getting any output this is most likely the problem.

debug($aVar); is IMO more useful than echo or pr as it will output the line number even if there is no other output (but you must have debug enabled!).

0

精彩评论

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