如何在我的home.ctp我的cakePHP应用程序请求一个变量? [英] how can i request a variable in my home.ctp of my cakePHP application?

查看:108
本文介绍了如何在我的home.ctp我的cakePHP应用程序请求一个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个页面使用MVC结构称为'sections'(视图位于app / views / sections文件夹,模型在模型文件夹和控制器在控制器文件夹)当我请求变量$ test,它工作正常没有任何错误..



当我想在我的home.ctp请求这个变量,它提供了一个错误,说变量是未定义的。



CakePHP中有任何方法可以在任何您想要的页面上请求此变量。



Thnx在MVC堆栈中,需要在控制器中设置变量和数据,然后将它们传递给你的控制器。



在你的例子中,你会想要 $ this-> set('myvar',$ item); 在您的 SectionsController 中,那么在您的视图中,您将能够 echo $ myvar 。 / p>

请务必在部分的 home() c $ c>控制器,否则它不会在您的首页视图中。


I created a page using the MVC structure called 'sections' ( view is located in the app/views/sections folder, model in the model folder and the controller in the controller folder) when i request the variable $test, it works fine without any errors..

When i want to request this variable in my home.ctp, it provides me with an error, saying that the variable is undefined..

Is there any way in cakePHP to request this variable on any page you want it to?

Thnx in advance!

解决方案

In the MVC stack, you need to set variables with data in your controller, and then pass them out to your view.

So in your example, you'll want to $this->set('myvar',$item); in your SectionsController, then in your view, you will be able to echo $myvar.

Be sure to set this in the home() method of your Sections controller, otherwise it won't be available in your home view.

这篇关于如何在我的home.ctp我的cakePHP应用程序请求一个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆