未定义的变量:yii中的模型

I am trying a sample application in yii.. I faced a problem when I created new view page name with cart.php. In this page I am trying to access model variable.Where it is saying undefined variable model..

View page

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'login-form',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
),
)); ?>


    <div>
    <?php echo $form->labelEx($model,'cartId:'); ?>
    <?php echo $form->textField($model,'cartId',array('size'=>20,'maxlength'=>120)); ?>
    <?php echo $form->error($model,'cartId'); ?>
    </div>



<?php $this->endWidget(); ?>
</div>

In your controler

public function actionYourPageName(){
    $model = YourModel::model()->findbypk($id);

    $this->render('YourPageViewFile', array('model'=>$model));
}

we need to add the code below to the action method where we redirect to ui page this will auto load the model to ui in yii framework

public function actionName(){
   //if u have id
    $model = YourModel::model()->findbypk($id);
           **or**
    //if u don't have id to retrive record
    $model = new YourModel();
            **or**
    // loadModel is default methode in controller
    'model'=>$this->loadModel($id),

    $this->render('YourPageViewFile', array('model'=>$model));
}

Use Below code you controller you have primary key "$id"

Public function actionPageName($id=NULL){
        $model = if($id)?YourModel::model()->findbypk($id):new YourModel();
        $this->render('page-name', array('model'=>$model));
 }