Dialog box appears, but didn't save or update on database. When i click on SAVE button, it just redirect to "create", but i was on "admin". It seems that it skip this part on controller:
if( $model->save() ) { // If callback is set run additional processing if( $this->callback !== null && method_exists( $controller, $this->callback ) ) $controller->{$this->callback}( $model ); // Accessing through AJAX, return success content if( $this->isAjaxRequest ) { // Output JSON encoded content echo CJSON::encode( array( 'status' => 'success', 'content' => $this->messages['success'], )); // Stop script execution Yii::app()->end(); }
I don't know if has some problem but i am using bootstrap.
Below my codes to help. Any help will be very appreciate. I am trying for a long time.
Controller:
<?php class PedidoAmbienteController extends Controller { /** * @var string the default layout for the views. Defaults to '//layouts/column2', meaning * using two-column layout. See 'protected/views/layouts/column2.php'. */ public $layout='//layouts/column1'; private $_model; /** * @return array action filters */ public function filters() { return array( 'accessControl', // perform access control for CRUD operations //'postOnly + delete', // we only allow deletion via POST request ); } /** * Specifies the access control rules. * This method is used by the 'accessControl' filter. * @return array access control rules */ public function accessRules() { return array( array('allow', // allow all users to perform 'index' and 'view' actions 'actions'=>array('index','view'), 'users'=>array('*'), ), array('allow', // allow authenticated user to perform 'create' and 'update' actions 'actions'=>array('create','update'), 'users'=>array('@'), ), array('allow', // allow admin user to perform 'admin' and 'delete' actions 'actions'=>array('admin','delete'), 'users'=>array('admin'), ), array('deny', // deny all users 'users'=>array('*'), ), ); } /** * Lists all models. */ public function actionIndex() { $dataProvider=new CActiveDataProvider('pedidoAmbiente'); $this->render('index',array( 'dataProvider'=>$dataProvider, )); } /** * Manages all models. */ public function actionAdmin() { $model=new pedidoAmbiente('search'); $model->unsetAttributes(); // clear any default values if(isset($_GET['pedidoAmbiente'])) $model->attributes=$_GET['pedidoAmbiente']; $this->render('admin',array( 'model'=>$model, )); } public function loadModel() { if( $this->_model === null ) { if( isset( $_GET['id'] ) ){ $this->_model = pedidoAmbiente::model()->findByPk( (int) $_GET['id'] ); //echo 'teste'; //exit(); } if( $this->_model === null ) throw new CHttpException( 404, 'The requested page does not exist.' ); } return $this->_model; } /** * Performs the AJAX validation. * @param pedidoAmbiente $model the model to be validated */ protected function performAjaxValidation($model) { if(isset($_POST['ajax']) && $_POST['ajax']==='pedido-ambiente-form') { echo CActiveForm::validate($model); Yii::app()->end(); } } /** * * Parâmetro para utilização do setflash para permitir automaticamente mensagens de feedback. * @param type $key * @param type $value * @param type $defaultValue */ public function setFlash( $key, $value, $defaultValue = null ) { Yii::app()->user->setFlash( $key, $value, $defaultValue ); } public function actions() { return array( 'create' => 'application.actions.CreateAction', 'view' => 'application.actions.ViewAction', 'update'=> 'application.actions.UpdateAction', 'delete' => 'application.actions.DeleteAction', ); } } ?>
view/pedidoambiente/admin
<?php /* @var $this PedidoAmbienteController */ /* @var $model pedidoAmbiente */ $this->breadcrumbs=array( 'Pedido Ambientes'=>array('index'), 'Manage', ); $this->menu=array( array('label'=>'List pedidoAmbiente', 'url'=>array('index')), array('label'=>'Create pedidoAmbiente', 'url'=>array('create')), ); Yii::app()->clientScript->registerScript('search', " $('.search-button').click(function(){ $('.search-form').toggle(); return false; }); $('.search-form form').submit(function(){ $.fn.yiiGridView.update('grid-view', { data: $(this).serialize() }); return false; }); "); ?> <h2>Visualizar / Adicionar Ambientes do Pedido </h2> <p> You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b> or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done. </p> <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search',array( 'model'=>$model, )); ?> </div><!-- search-form --> <?php $this->widget( 'ext.EUpdateDialog.EUpdateDialog' ); echo CHtml::link( 'Ambientes', array( 'create' ), array( 'class' => 'update-dialog-open-link', 'data-update-dialog-title' => Yii::t( 'app', 'Inserir Ambiente' ), )); ?> <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'grid-view', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( 'Pedido_idPedido', 'ambiente_idambiente', 'previsao_medicao', 'realizado_medicao', 'realizado_projeto', 'aprovacao_arquiteto', array( 'class'=>'CButtonColumn', 'buttons' => array( // Delete button 'delete' => array( 'click' => 'updateDialogOpen', 'url' => 'Yii::app()->createUrl("/pedidoAmbiente/delete", array( "id" => $data->primaryKey ) )', 'options' => array( 'data-update-dialog-title' => Yii::t( 'app', 'Delete confirmation' ), ), ), // Update button 'update' => array( 'click' => 'updateDialogOpen', 'options' => array( 'data-update-dialog-title' => Yii::t( 'app', 'Atualizar Ambiente' ), ), ), // View button 'view' => array( 'click' => 'updateDialogOpen', 'options' => array( 'data-update-dialog-title' => Yii::t( 'app', 'Visulizar Ambiente' ), ), ), ), ), ), )); ?>