Yii索引页不打印函数内部的值


Yii index page does not print values inside a function

php?r=我的Yii演示应用程序的站点/索引。。。我在那里放了一个名为hello的函数,但它没有进入该函数内部(helloworld不会打印出来)。。有人能帮我这个吗

    <?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
 // <h1>Welcome to <i><?php echo CHtml::encode(Yii::app()->name); ?></i></h1>
 <?php
 function hello(){
     echo 'Hello world';
 }
?>
// <p>Congratulations! You have successfully created your Yii application.</p>
// <p>You may change the content of this page by modifying the following two files:</p>
// <ul>
    // <li>View file: <code><?php echo __FILE__; ?></code></li>
    // <li>Layout file: <code><?php echo $this->getLayoutFile('main'); ?></code></li>
// </ul>
// <p>For more details on how to further develop this application, please read
// the <a href="http://www.yiiframework.com/doc/">documentation</a>.
// Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
// should you have any questions.</p>

您只声明了函数。你需要调用函数来执行它。

function hello(){
    echo 'Hello world';
}
hello();

不过,在视图中声明函数是非常糟糕的风格。我认为在使用框架之前,您应该了解更多关于编程的知识。