Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Cjuiautocomplete Filed Showing Error

$
0
0
I am just newbie to the yii framework. Currently I have two tables one for sales and other for stores Sales table is looking like this

  ==============
      sales
  ==============
  id
  store_id


store table is looking like this

 ==============
      Stores
  ==============
  id
  store_name
  store_location


Now in sales view form(_form.php) I have rendered both sales and stores. In sales controller the code for action create is like this

 public function actionCreate()
  {
    $model=new Sales;
    $stores = new Stores;

    // Uncomment the following line if AJAX validation is 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 get all the stores name in dropdown list I made my code like 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 I want the cjuiautocomplete field so that when someone will press any key then it will start to show the suggesions stores name. For that I just came through this link

and just like the docs I made the EAutoCompleteAction.php under protected/extension directory Then I just made my controller code like this 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 the model i will search
        ),
      );
    }


and in view file of sales(_form.php) I made the code like 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 all when I am doing the search by keywords it is showing 404 error in console panel of firebug. The requested search url in firebug was like this (ads was my search query in store name field)

http://localhost/WebApp/index.php?r=stores/store_name&term=ads

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>