我需要使用CAutoComplete创建一个下拉列表。一切都设置好了,这是我的行动代码:
<?php
public function actionSuggestCharacter() {
if(Yii::app()->request->isAjaxRequest && isset($_GET['q'])) {
$name = $_GET['q'];
$criteria = new CDbCriteria;
$criteria->condition='`Character` LIKE :keyword';
$criteria->params=array(':keyword'=>"$name%");
$criteria->limit = 5;
$suggestions = zCharacter::model()->findAll($criteria);
$returnVal = '';
foreach($suggestions as $suggestion) {
$returnVal .= $suggestion->Character."\n";
}
if (isset($suggestion)) {
echo $returnVal;
}
$criteria->condition='`Character` LIKE :keyword';
$criteria->params=array(':keyword'=>"%$name%");
$criteria->limit = 5;
$suggestions = zCharacter::model()->findAll($criteria);
$returnVal = '';
foreach($suggestions as $suggestion) {
$returnVal .= $suggestion->Character."\n";
}
if (isset($suggestion)) {
echo $returnVal;
}
}
}
?>
这段代码的作用是它在开头显示前5个匹配关键字,接下来的5个匹配在任何地方都有关键字。
实施例。假设用户在输入字段“pdd”中输入(并不重要,可以是任何文本),因此自动完成返回的结果将如下所示:
1. pddtext...
2. pddtext...
3. pdd_some_other_text
4. pdd_text
5. pdd_text
1. text_text_pdd
2. text_pdd_text
3. etc...
问题是我需要通过某种线(<hr>
或<div>
与边框分隔这两个块)。我怎么能这样做?
谢谢。
答案 0 :(得分:2)
你不能做这样的事吗?
<?php
public function actionSuggestCharacter() {
if(Yii::app()->request->isAjaxRequest && isset($_GET['q'])) {
...
if (isset($suggestion)) {
echo $returnVal;
}
echo "Hey this is the delimiter\n";
$criteria->condition='`Character` LIKE :keyword';
....
}
}
?>
然后在客户端检查此字符串,当您遇到“”嘿,这是分隔符“将其替换为您的分隔符。