【发布时间】:2013-07-16 08:48:07
【问题描述】:
我正在做一个小应用程序。为此,我有两张桌子,比如 sles 和 stores 销售表是这样的
============
Sales
============
id
store_id
Stores
=============
id
store_name
store_location
store_code
description
我已经为这两个表完成了模型和 CRUD。在商店表中,我根据表输入了一些值。 现在在销售控制器中,我已经呈现了销售和商店。所以在这里我的动作创建看起来像这样
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,
));
}
而在sales(_form.php)中是这样的
<div class="row">
<?php echo $form->labelEx($stores,'store_name'); ?>
<?php echo $form->textField($stores,'store_name',array('size'=>60,'maxlength'=>80)); ?>
<?php echo $form->error($stores,'store_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($stores,'store_location'); ?>
<?php echo $form->textField($stores,'store_location',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($stores,'store_location'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($stores,'store_code'); ?>
<?php echo $form->textField($stores,'store_code',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($stores,'store_code'); ?>
</div>
现在,当我进行销售时,我希望当我通过输入键输入一个商店名称时,它将开始显示相关的stores names,并且store_location 和store_code 将自动填充。现在有人可以告诉我该怎么做吗?任何帮助和建议都将不胜感激。非常感谢。
编辑 this 只能自动完成一个字段。但我希望所有其他相关字段也应该自动完成。
【问题讨论】:
-
你需要像这个演示papermashup.com/demos/autosuggest一样使用自动建议。完成触发jquery ajax后根据名称自动填充从数据库中获取字段
-
任何其他扩展或任何 Yii 演示
-
我认为你不能直接使用你需要使用jquery Ajax .to check from database
标签: php yii yii-extensions