将变量从控制器传递到 Yii 中的视图 [英] pass variables from controller to view in Yii

查看:24
本文介绍了将变量从控制器传递到 Yii 中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在相应视图中使用控制器中指定的变量.这是我的代码:

I cannot use the variables specified in controller in the corresponding view. Here is my code:

public function actionHelloWorld()
    {

        $this->render('helloWorld',array('var'=>'this is me'));
    }

在helloWorld.php(查看文件)中:

In the helloWorld.php (view file):

<h1>Hello, World!</h1>
<h3><?php echo $var; ?></h3>

它只打印出Hello, World!",看起来 $var 在视图中是不可访问的.有人吗?

It only prints out "Hello, World!", looks like $var is unaccessible in the view. Anyone?

推荐答案

"var" 是 PHP 中的保留字,因此您将无法为变量使用该名称.请参阅:http://www.php.net/manual/en/reserved.keywords.php

"var" is a reserved word in PHP, so you won't be able to use that name for your variable. See: http://www.php.net/manual/en/reserved.keywords.php

尝试使用不同的变量名称,它应该可以工作.

Try using a different variable name and it should work.

这篇关于将变量从控制器传递到 Yii 中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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