Yii 未定义变量:模型

Yii 未定义变量:模型,yii,Yii,我是Yii的新手,现在正在学习。这里我试图从数据库的users表中获取用户列表 以下是用于查看的“我的用户”控制器功能: class UsersController extends Controller { public function actionIndex() { $this->render('index'); } public function actionView() { $model = new User

我是Yii的新手,现在正在学习。这里我试图从数据库的users表中获取用户列表

以下是用于查看的“我的用户”控制器功能:

class UsersController extends Controller
{
    public function actionIndex()
    {
        $this->render('index');
    }

    public function actionView()
    {
        $model = new Users;

        $this->render('view',array(
        'model'=>$model,
        ));
    }
}
以下是我的用户模型:

class Users extends CActiveRecord
{

public static function model($className=__CLASS__)
{
    return parent::model($className);
}

/**
 * @return string the associated database table name
 */
public function tableName()
{
    return '{{users}}';
}

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('fname, lname, email', 'required'),
        array('fname, lname', 'length', 'max'=>50),
        array('email', 'length', 'max'=>100),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, fname, lname, email', 'safe', 'on'=>'search'),
    );
}

/**
 * @return array relational rules.
 */
public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
    );
}

/**
 * @return array customized attribute labels (name=>label)
 */
public function attributeLabels()
{
    return array(
        'id' => 'ID',
        'fname' => 'First Name',
        'lname' => 'Last Name',
        'email' => 'Email',
    );
}

/**
 * Retrieves a list of models based on the current search/filter conditions.
 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
 */
public function search()
{
    // Warning: Please modify the following code to remove attributes that
    // should not be searched.

    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('fname',$this->fname,true);
    $criteria->compare('lname',$this->lname,true);
    $criteria->compare('email',$this->email,true);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}
}
以下是我的看法:

<h1>Users</h1>

<p>
Below is the list of users, here you may add user.
</p>

<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
    'id',
    'fname',
    'lname',
    'email',
),
)); ?>

<div class="view">

<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?     >
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('fname')); ?>:</b>
<?php echo CHtml::encode($data->fname); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('lname')); ?>:</b>
<?php echo CHtml::encode($data->lname); ?>
<br />

<b><?php echo CHtml::encode($data->getAttributeLabel('email')); ?>:</b>
<?php echo CHtml::encode($data->email); ?>
<br />

</div>
用户

下面是用户列表,您可以在这里添加用户。

: :
:
:

我收到一个PHP通知,上面说未定义的变量:model,请提前帮助我,谢谢。

看起来您正在粘贴_view.PHP。
请确保将
$model
变量从
view.php
交给
\u view.php
,因为在
actionView()
中,您只将其交给了“view”。

谢谢您的回答,但您可以更具体地说,我应该做什么确保将$model变量从view.php交给了\u view.php。查看
renderPartial()
调用in view.php:)是否显示所有用户?然后您应该使用类似于
zii.widgets.CListView的东西。顺便说一句,该视图用于
actionIndex
actionView
?感谢您的回答,该视图用于actionView