Php Yii:另一个表的标题(字符串)如何在视图页面中变成数组?

Php Yii:另一个表的标题(字符串)如何在视图页面中变成数组?,php,yii,frameworks,Php,Yii,Frameworks,我使用外键打印一些数据,但我不知道它是如何在我的视图页面中转换为数组的 echo ucfirst(User::model()->findByPk($model->postby_id)->username); $this->widget('bootstrap.widgets.TbDetailView', array( 'data' => $model, 'attributes' => array(`enter code here`

我使用外键打印一些数据,但我不知道它是如何在我的视图页面中转换为数组的

echo ucfirst(User::model()->findByPk($model->postby_id)->username);
$this->widget('bootstrap.widgets.TbDetailView', array(
    'data' => $model,
    'attributes' => array(`enter code here`
        'id',
        'title',
        'question',
        'detail',
        //'postby_id',
        array(
            'name' => 'Post By',
            'value' => ucfirst(User::model()->findByPk($model->postby_id)->username),
        ),
        'verified',
        'verifiedby_id',
        'post_date',
        'hits',
        'status',
    ),
));
试试这个:

array(
        'name' => 'Post By',
        'value' => echo ucfirst(User::model()->findByPk($model->postby_id)->username),
    ),
或:

更新: 从中,“value”也可以是匿名函数,其返回值将用作值。函数的签名应该是function($data),其中数据指的是细节视图小部件的数据属性。。我认为以下解决方案可以帮助您:

首先在模型中定义一个函数:

 public function getUsername($postby_id)
 {
     return ucfirst(User::model()->findByPk($postby_id)->username);
 }
然后,您可以在视图中看到:

 array(
        'name' => 'Post By',
        'value' =>$model->getUsername($model->postby_id)),
    ),

ucfirst(User::model()->findByPk($model->postby_id)->username)的结果是什么?
?谢谢@hamed,我尝试了两个选项,但都出现了语法错误。IDE告诉我们echo对于第一个选项来说是意外的&}也是意外的。ucfirst(User::model()->findByPk($model->postby_id)->username)的结果是什么??这是我想要的字符串。$a=ucfirst(User::model()->findByPk($model->postby_id)->username);数组('name'=>'Post By','value'=>$a[0],),现在它可以打印字符串的第一个字符。同样的错误。错误500,system()要求参数1为字符串,对象为给定
 array(
        'name' => 'Post By',
        'value' =>$model->getUsername($model->postby_id)),
    ),