public function run() { /*Top nxb*/ $criteria = new CDbCriteria(); $criteria->limit = 3; $criteria->order = 'frequency desc'; $list = Nxb::model()->findAll($criteria); $this->render('top_nxb', array('list' => $list)); }
/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $book =Book::model()->findByPk($id); $id_nxb=$book->nxb; $criteria= new CDbCriteria(); $criteria->compare('id',$id_nxb); $nxb = Nxb::model()->findAll($criteria); $this->render('view',array( 'model'=>$this->loadModel($id), 'nxb'=>$nxb, 'book'=>$book, )); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Nxb the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Nxb::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<div class="form"> <?php $form = $this->beginWidget('CActiveForm', array('id' => 'book-form', 'enableAjaxValidation' => false)); ?> <?php echo $form->errorSummary($model); ?> <div class="row"> <p>Nhập tên nhà xuất bản</p> <?php echo $form->dropDownList($model, 'nxb', CHtml::listData(Nxb::model()->findAll(), 'id', 'name'), array('class' => 'form-control input-traodoi')); ?> <?php echo $form->error($model, 'nxb'); ?> </div> <div class="row"> <p>Mời bạn nhập tên tác giả</p> <?php $this->widget('CAutoComplete', array('model' => $model, 'attribute' => 'author', 'url' => array('suggestTags'), 'multiple' => true, 'htmlOptions' => array('size' => 50, 'class' => 'form-control input-traodoi'))); ?> <p class="hint">Có thể nhập được nhiều tác giả</p> <?php echo $form->error($model, 'author'); ?>