View:
<div class="row">
<?php echo $form->labelEx($model, 'attribute'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model' => $model,
'attribute' => 'emp',
'sourceUrl' => Yii::app()->createUrl('/controller/action'),
'options' => array(
'minLength' => '1',
'select' => 'js:function(event, ui) {
$("#field1").val(ui.item.label);
$("#field2").val(ui.item.value);
return false;
}'
),
'htmlOptions' => array('size' => 60),
));
?>
<?php echo $form->error($model, 'attribute'); ?>
</div>
Controller:
public function actionAutocomplete($term) {
//the $term parameter is what the user typed in on the control
//send back an array of data:
$criteria = new CDbCriteria;
$criteria->compare('field2', $term, true);
$model = Model::model()->findAll($criteria);
foreach ($model as $value) {
$array[] = array('value' => trim($value->field1), 'label' => trim($value->field2));
}
echo CJSON::encode($array);
Yii::app()->end();
}
Friday, 25 January 2013
PHP - Enable ldap.dll for xampp or Windows server
- From C:\xampp\php copy the following files to C:\Windows\system
- libeay32.dll
- libsasl.dll
- ssleay32.dll
- Enable php_ldap.dll at php.ini
Thursday, 24 January 2013
Yii connect to MS SQL Server
- Dowload Drivers and DLL for PHP http://msdn.microsoft.com/en-us/library/cc296170.aspx
- Edit php.ini enable extension
- Edit config/main.php db connection string
'db' => array(
'connectionString' => 'sqlsrv:Server=tcp:123.345.444.333;Database=myDB',
'username' => 'username',
'password' => 'password',
),
Wednesday, 16 January 2013
Yii Ajax loader
<?php
Yii::app()->clientScript->registerScript('loaderScript', '
$("#loader")
.hide()
.ajaxStart(function() {
$(this).show();
})
.ajaxStop(function() {
$(this).hide();
});', CClientScript::POS_END);
?>
<?php echo CHtml::image('images/ajax-loader.gif', '', array('id' => 'loader', 'style' => 'margin-left:15px;'));?>
Thursday, 3 January 2013
Yii CGridView with CCheckBoxColumn with ajaxbutton
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'orders-products-grid',
'dataProvider' => $model->search(),
'columns' => array(
array(
'header' => 'Item #',
'value' => '++$row',
),
'products_name',
'products_quantity',
array(
'header' => 'Price',
'value' => '"$".number_format($data->final_price*$data->products_quantity,2)',
),
array(
'header' => 'Confirmed?',
'value' => '$data->bought == 0? "No" : "Yes"',
),
array(
'class' => 'CCheckBoxColumn',
'selectableRows' => 2,
'checked' => '$data->bought==1',
'id' => 'boughtCheck'
)
),
));
?>
<?php
echo CHtml::ajaxButton('Confirm', yii::app()->createUrl('site/checkBought'), array(
'type' => 'POST',
'data' => 'js:{value : $.fn.yiiGridView.getChecked("orders-products-grid","boughtCheck")}',
'success'=>'js:function(data){
$.fn.yiiGridView.update("orders-products-grid");
}'
));
Subscribe to:
Posts (Atom)