Yii框架CJUIautocomplete显示错误

时间:2013-07-15 11:59:33

标签: php yii

我只是yii framework的新手。目前我有两张桌子 一个用于sales,另一个用于stores Sales table看起来像这样

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

store table看起来像这样

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

现在在销售视图表单(_form.php)中,我已经呈现了销售和商店。   在销售控制器中,动作创建的代码就像这样

  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,
    ));
  }

要在下拉列表中获取所有商店名称,我就像这样编写了我的代码

    <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>

但是在这里我想要cjuiautocomplete字段,以便当有人按任意键时它会开始显示建议商店名称。为此,我刚刚通过了this link

就像我在保护/扩展目录下制作EAutoCompleteAction.php的文档一样   然后我在销售控制器

中制作了这样的控制器代码
 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
        ),
      );
    }

并且在销售视图文件(_form.php)中我创建了这样的代码

    <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,
        ),
  )); ?>

毕竟当我按关键字进行搜索时,它在firebug的控制台面板中显示404错误。   在firebug中请求的搜索网址是这样的(广告是我在商店名称字段中的搜索查询)

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

这里有人帮忙吗?

1 个答案:

答案 0 :(得分:0)

您忘记将示例aclist中的操作名称更改为store_name

public function actions()
{
  return array(
    'store_name'=>array( // << Array key is action name
      'class'=>'application.extensions.EAutoCompleteAction',
      'model'=>'Stores', //My model's class name
      'attribute'=>'store_name', //The attribute of the model i will search
    ),
  );
}