![](/img/trans.png)
[英]How can I handle in PHP a subfolder's index.php as main index.php
[英]How can I use cjuiautocomplete on index.php's form?
我有index.php,我正在其中實現搜索功能,該功能在工作,例如用戶輸入一些公司名稱,然后輸入一些城市名稱,然后提交從數據庫中檢索到的表格。 現在,我的下一個任務是使用cjuiautocomplete
實現表單提交。 就像用戶開始輸入商家名稱時一樣,商家應該在下拉列表中降落。 我遇到的主要障礙是我在index.php中。 我正在關注此http://www.yiiframework.com/wiki/162/a-simple-action-for-cjuiautocomplete/,但這是用於控制器的查看文件。 我如何在我的index.php中實現這一點。 下面給出的是我在index.php中的表格。
<form action="business/searchingtesting" method="GET">
<div class="form-group form-group-lg">
<h2 class="title">Find the best places to eat, drink, shop, or visit in Islamabad. </h2>
<div class="col-sm-5 col-md-5 col-lg-5 col-md-offset-1">
<input type="text" class="form-control" name="business" id="lg" placeholder="I'm looking for....">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<input type="text" class="form-control" id="sm" name="city" placeholder="Islamabad">
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<input type="submit" class="btn btn-primary btn-lg" value="submit">
</div>
</div>
</form>
如果我遵循上面的鏈接,並在表單中使用以下代碼,則會收到此錯誤“未定義的變量模型”。
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'attribute' => 'my_name',
'model' => $model,
'sourceUrl' => array('my/aclist'),
'name' => 'business_name',
'options' => array(
'minLength' => '3',
),
'htmlOptions' => array(
'size' => 45,
'maxlength' => 45,
),
)); ?>
首先閱讀文檔 。 您可以像沒有模型一樣將CJuiAutoComplete與模型一起使用。 要與模型一起使用,您需要指定兩個參數: model
和attribute
。 如果不帶模型使用它,則僅name
。 如我所見,您沒有在表單中使用模型,因此此示例適合您:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'my_name',
'sourceUrl' => array('/my/aclist'), // you need first slash if you want properly working URL from web root
));
<form action="business/searchname" method="GET">
<div class="form-group form-group-lg">
<h2 class="title">
Find the best places to eat, drink, shop, or visit in Islamabad.
</h2>
<div class="col-sm-5 col-md-5 col-lg-5 col-md-offset-1">
<?php
$model = Business::model()->findAll();
$modelcity = Address::model()->findAll(array(
'select' => 't.city',
'group' => 't.city', //selecting distinct values as many businesses hass same cities, so the drop down was filled with only one city
'distinct' => true,
));
foreach ($model as $mo) {
$store[] = $mo->business_name;
}
foreach ($modelcity as $c) {
$city[] = $c->city;
}
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'business',
'source' => array_values($store),
// additional javascript options for the autocomplete plugin
'options' => array(
'minLength' => '2',
),
'htmlOptions' => array(
'style' => 'height:45px;width:415px;',
'placeholder' => ' I am Looking for................ ',
),
));?>
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'city',
'source' => array_values($city),
// additional javascript options for the autocomplete plugin
'options' => array(
'minLength' => '2',
),
'htmlOptions' => array(
'style' => 'height:45px; width:250px;',
'placeholder'=>' City................ ',
),
));
?>
</div>
<div class="col-sm-3 col-md-3 col-lg-3">
<input type="submit" class="btn btn-primary btn-lg" value="submit"/>
</div>
</div>
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.