i newbie yii framework. have 2 tables 1 sales
, other stores
sales table
looking this
============== sales ============== id store_id
store table
looking this
============== stores ============== id store_name store_location
now in sales view form(_form.php) have rendered both sales , stores. in sales controller code action create this
public function actioncreate() { $model=new sales; $stores = new stores; // uncomment following line if ajax validation needed // $this->performajaxvalidation($model); if(isset($_post['sales']$_post['stores'])) { $model->attributes=$_post['sales']; $stores->attributes = $_post['stores']; $valid = $model->validate(); $valid = $stores->validate(); if($valid) { $stores->save(false); $model->store_id = $stores->getprimarykey(); $model->save(false); $this->redirect(array('view','id'=>$model->id)); } } $this->render('create',array( 'model'=>$model, 'stores' => $stores, )); }
to stores name in dropdown list made code this
<div class="row"> <?php echo $form->labelex($stores,'store_name'); ?> <?php echo $form->dropdownlist($stores,'store_name', chtml::listdata(stores::model()->findall(), 'store_name', 'store_name'), array('empty'=>'--select--')) ?> <?php echo $form->error($stores,'store_name'); ?> </div>
but here want cjuiautocomplete field when press key start show suggesions stores name. came through this link
and docs made eautocompleteaction.php under protected/extension directory made controller code in sales controller
public function actions() { return array( 'aclist'=>array( 'class'=>'application.extensions.eautocompleteaction', 'model'=>'stores', //my model's class name 'attribute'=>'store_name', //the attribute of model search ), ); }
and in view file of sales(_form.php) made code this
<div class="row"> <?php echo $form->labelex($stores,'store_name'); ?> <?php $this->widget('zii.widgets.jui.cjuiautocomplete', array( 'attribute'=>'store_name', 'model'=>$stores, 'sourceurl'=>array('stores/store_name'), 'name'=>'store_name', 'options'=>array( 'minlength'=>'3', ), 'htmloptions'=>array( 'size'=>45, 'maxlength'=>45, ), )); ?>
after when doing search keywords showing 404 error in console panel of firebug. requested search url in firebug (ads search query in store name field)
http://localhost/webapp/index.php?r=stores/store_name&term=ads
any 1 here help?
you forgot change action name sample aclist
store_name
:
public function actions() { return array( 'store_name'=>array( // << array key action name 'class'=>'application.extensions.eautocompleteaction', 'model'=>'stores', //my model's class name 'attribute'=>'store_name', //the attribute of model search ), ); }
Comments
Post a Comment