Php yii,从数据库中的文本字段中搜索值
和我的数据库: id:varchar8 姓名:varchar20 地点:varchar50 我想在数据库中搜索id,然后返回名称和位置值。如何建立其模型和控制器。 任何帮助都将不胜感激,谢谢 首先使用gii ref生成模型 然后,您可以在控制器中添加以下功能Php yii,从数据库中的文本字段中搜索值,php,html,database,search,yii,Php,Html,Database,Search,Yii,和我的数据库: id:varchar8 姓名:varchar20 地点:varchar50 我想在数据库中搜索id,然后返回名称和位置值。如何建立其模型和控制器。 任何帮助都将不胜感激,谢谢 首先使用gii ref生成模型 然后,您可以在控制器中添加以下功能 在yii中做脚手架,它会自动创建搜索功能以及网格。 I have this code on my view, <div class="text-id-box"> <?php echo CHtml::textField($
在yii中做脚手架,它会自动创建搜索功能以及网格。
I have this code on my view,
<div class="text-id-box">
<?php echo CHtml::textField($model,'id'); ?>
</div>
<div class="submit-box">
<?php echo CHtml::button('Search', array(
'submit' => array('SiteController/actionSearch',
array('id'=>$id)))); ?>
</div>
public function actionSearch($id)
{
$model= new Yourmodel;
$model=Yourmodel::model()->findByPk($id);
//you will get the row for particular id
// and you can access it by $model->name $model->location
// render the required page and access to model object to get the name and location.
}