/** * 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 the ID of the model to be loaded */ public function loadModel($id) { $model=Comentario::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
public function actionAutocompletesearch() { $q = "%" . $_GET['term'] . "%"; $result = array(); if (!empty($q)) { $criteria = new CDbCriteria(); $criteria->select = array('id', "CONCAT_WS(' ',nombre) as nombre"); $criteria->condition = "lower(CONCAT_WS(' ',nombre)) like lower(:nombre) "; $criteria->params = array(':nombre' => $q); $criteria->limit = '10'; $cursor = Comentario::model()->findAll($criteria); foreach ($cursor as $valor) { $result[] = array('label' => $valor->nombre, 'value' => $valor->nombre, 'id' => $valor->id); } } echo json_encode($result); Yii::app()->end(); }
</div> </div> </div> <br /> <br /> <div class="row"> <div class="col-xs-12 col-md-7"> <?php echo CHtml::statefulForm($this->createUrl('salvarComentario'), "post", array('id' => 'formComentarioAnuncio')); $params = array(); $condition = " 1=1 "; if (isset($this->anuncio) && $this->anuncio != '') { $condition = $condition . ' AND anuncio=:anuncio'; $params[':anuncio'] = $this->anuncio; } $comentarios = Comentario::model()->findAll(array('condition' => $condition, 'params' => $params, 'order' => 'data desc')); $ultimoComentario = new Comentario(); if (count($comentarios) > 0) { $ultimoComentario = end($comentarios); } ?> <div class="form-group"> <div class='col-md-6'><label for="descricao">Comentários (<?php echo count($comentarios); ?> ) </label></div><div class="col-md-6 text-right"><h5><small><?php echo count($comentarios) > 0 ? 'Último comentário <span class="glyphicon glyphicon-calendar" aria-hidden="true"></span> ' . Date('d/m/Y H:i', strtotime($ultimoComentario->data)) : ''; ?> </small></h5></div> <textarea class='form-control' name='comentario' id='comentario' ng-model='comentario.comentario' placeholder='Deixe seu comentário aqui.' maxlength='200'></textarea> </div>
); ?> </td> <td style="width: 50%"> </td> </tr> </table> <h1>Comentários</h1> <?php $this->widget('zii.widgets.CListView', array( 'dataProvider'=>$comentarios, 'itemView'=>'//comentario/view' ) ); ?> <br /> <?php if( !Yii::app()->user->isGuest ) { $mod = Comentario::model(); $mod->isNewRecord = true; echo $this->renderPartial('_form_comment', array( 'model'=>$mod, 'idevento'=>$evento->idevento, 'iduser'=>$utilizador->oid ) ); } ?> <br />