Normally we will use the form submit action via post or get method with page submit option. With out page refresh we can submit the form using ajax concept. It will be faster than page reload. This post will help you to under stand AjaxSubmitButton instead of submitButton in yii. ajaxSubmitButton With Form <div class=”form”> […]
Category Archives: Yii Framework
This is one of the way to send data dynamicallay in ajaxbutton request of yii. When you click on ajaxbutton We will get the selected checkbox value and send this via ajax <?php Yii::app()->clientScript->registerScript(‘checkBoxSelect’, ” function callData(){ fileid= $(\”input[name=’usergroup[]’]:checked\”).map(function() { return this.value; }).get(); return ‘id=’+fileid; } “); ?> <?php echo CHtml::ajaxButton(‘User’,CController::createUrl(‘user/active’), array( ‘type’ =>’POST’, ‘data’=>”js:callData()”, […]
Example 1: In view.php page Write Follwing source code <?php echo CHtml::ajaxButton( ‘Submit request’, array(‘test/function’), array(‘data’=>array(‘test’=>$model->id)), array(‘update’=>’#update_selector’) //this is the update selector of yours $(‘#update_selector’).load(url); ); ?> In controller.php write following source code public function actionFunction() { if(Yii::app()->request->isAjaxRequest){ $this->renderPartial(“_form”,array(‘model’=>$model),false,true); Yii::app()->end(); } } Example 2: <?php echo CHtml::ajaxButton( ‘Save’, array(‘user/useraction’), array(‘data’=>array( ‘id’=>$model->year_id, ‘usertype’=>’js:$(“#usertype”).val()’, ‘username’=>’js:$(“#username”).val()’, ) ‘type’=>’POST’, […]
This turorial have the details of dynamic data insertion to dropdownlist using ajax. I added the source code below for this concept. We have two dropdownlist in form “usercategory”,”usertype”. When we change the usercategory, usercategory related usertype will show in “usertype” dropdownlist. In view.php <div class=”row”> <?php echo $form->labelEx($model,’usercategory’); ?> <?php $categories=Yii::app()->Datacomponent->usercategory(); echo $form->dropdownlist($model, ‘usercategory’, […]
This tutorial will help you to understand the details of yii ajax request and response from controller. I will change the product list based on category change via ajax. When i change the “category” dropdown, Ajax will send the request to “site/productlist” controller. Now controller will get and process the data then finally It will […]
Ajax Submit Button Ajax Button Ajax Link Ajax Support Ajax Submit Button Ajax submit button can submit the current form in POST method. public static string ajaxSubmitButton( string $label, mixed $url, array $ajaxOptions=array ( ), array $htmlOptions=array ( ) ) $lable-the button label $url – the URL for the AJAX request. If empty, it is […]
Hi i used CActiveDataProvider everytime to retrieve the data for CGridView.But one of my project needed custom query in criteria and have to show the result in CGridView. During that time i found MyActiveDataProvider concept with extends of CActiveDataProvider. I applied that concept and working fine for me. I added that source code for you. I think […]
CDbCriteria is the one of best support in yii framework. CDbCriteria is used to assign the values or property in query. Using cdbcriteria property we can assign condition, order, limit, scopes etc for query. It have some methods to apply condition for model or sql table like addCondition(), addInCondition() etc . alias Condition Distinct Group […]
Sample <?php $criteria = new CDbCriteria; $criteria->mergeWith(array( ‘join’=>’LEFT JOIN user_group ug ON ug.user_id = t.id’, ‘condition’=>’ug.group_id = 0 OR ug.group_id IS NULL’, )); User::model()->findAll($criteria); ?> Sample <?php class Mymodel extends CActiveRecord { public function relations() { return array( ‘mySecondTable’ => array(self::HAS_MANY, ‘MySecondTable’, ‘second_table_id’), ); } } public function searchWithRelated() { $criteria = new CDbCriteria; //without […]
Yii framework model have search() function. We can create more function like search. I created new function ‘searchcategory’ and i added some custom function to searchcategory() function. Example public function searchcategory() { $criteria=new CDbCriteria; $condition=”; $categoryname=$this->categoryname; if($this->categoryname1!=”){ $categorystring=$this->likecategoryname($this->categoryname1); if($categorystring!=”){ $condition=”categoryidIN (“.$categorystring.”)”; } } if($categoryname!=”){ $categoryidstring=$this->likecategoryname($categoryname); if($categoryidstring!=”){ if($condition!=”) $condition.=’ AND ‘; $condition.=”categoryid IN (“.$categoryidstring.”)”; } } […]