如何从Yii Framework中的模型获取特定记录

时间:2014-08-13 05:49:13

标签: php yii

我试图从YII框架中的表中获取记录,不知道它为什么不起作用。

public function actionGetStarted($id) {
    $curUser = new Customer;
    $curUser->findByPk($id);
    if (!$curUser)
        throw new CHttpException(403, 'Customer Does\'t exists');
    $getStarted = AppContent::model()->findAll();
    $this->render('getStarted', array('getStarted' => $getStarted));
}

1 个答案:

答案 0 :(得分:2)

你的语法不符合Yii。

public function actionGetStarted($id) {
    $curUser = new Customer;
    $user=$curUser::model()->findByPk($id);
     e($curUser->attributes);// check this line.Also it seems incorrect
     if (empty($user))
        throw new CHttpException(403, 'Customer Does\'t exists');
     // saving current customer to session
     $getStarted = AppContent::model()->findAll();
     $this->render('getStarted', array('getStarted' => $getStarted));

}