gpt4 book ai didi

php - 我被要求修复搜索功能中的错误。我在 yii 上不断收到 CDbException

转载 作者:行者123 更新时间:2023-11-29 06:41:32 25 4
gpt4 key购买 nike

我不是该项目的一部分,而且我对 yii 真的很陌生,所以找到所有东西的位置一直是一个挑战。

每次我在搜索栏中输入内容时,php 都会给我以下错误:

 CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'first_name' in 'where clause'. The SQL statement executed was: SELECT * FROM `persons` `t` WHERE CONCAT(upper(first_name),' ',upper(last_name)) like :tag or upper(email) like :tag

.tag {
08 background-color: yellow;
09 }
10 </style>
11 -->
12 <?php
13 $this->breadcrumbs=array(
14 'Search'=>array('/search'),
15 'Search',
16 );?>
17
18
19 <?php if (($personDataProvider->itemCount + //ERROR POINTS HERE
20 //$galleryDataProvider->itemCount +
21 $blogDataProvider->itemCount +
22 $forumDataProvider->itemCount +
23 $announcementDataProvider->itemCount +
24 $pollsDataProvider->itemCount +
25 $eventsDataProvider->itemCount +
26 $jobsDataProvider->itemCount) == 0) {
27 ?>
28
29 <div>
30
31 <h2 style="color:#259CB1">No Results Found for <i><?=$tag?></i>.</h2>

作为额外引用,我将把我的 PersonController 类放在这里,因为我真的很困惑这些数据提供者的位置!

        public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Persons');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}

public function loadModel($id)
{
$model=Persons::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

public function loadModel2($id)
{
$model=User::model()->findByAttributes(array('party_id'=>$id));
if($model===null)
{
echo 'hi';
exit;
throw new CHttpException(404,'The requested page does not exist.');
}
return $model;
}

public function loadModel3($id)
{
$model=Organizations::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

这是我的模型人物页面:

        public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('party_id',$this->party_id,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('company_name',$this->company_name);
$criteria->compare('middle_name',$this->middle_name,true);
$criteria->compare('dob_year',$this->dob_year);
$criteria->compare('dob_month',$this->dob_month);
$criteria->compare('dob_day',$this->dob_day);
$criteria->compare('nickname',$this->nickname,true);
$criteria->compare('country',$this->country,true);


return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

我检查了 PersonController 和 search.php 页面,但我不太确定在哪里可以找到 $PersonDataProvider 以便修复此错误!

根据要求,我已经为 actionSearch() 添加了 Controller 并且我看到了“first_name”(它在我的数据库中不存在)但它仍然要求我定义 Person--------------------更新--------------------

    public function actionSearch()
{

if(!isset($_GET['tag'])){
Yii::app()->request->redirect(Yii::app()->createUrl('news/index/page/1'));
}
$tag = trim($_GET['tag']);

if(empty($tag)){
Yii::app()->request->redirect(Yii::app()->createUrl('news/index/page/1'));
}

$conditionforadmin = '';
if(Yii::app()->user->isAdmin() == 0)
{
$conditionforadmin = 'and end_date > now() ';
}

$personDataProvider = new CActiveDataProvider('Persons',array(
'criteria'=>array(
'condition'=>'CONCAT(upper(first_name),\' \',upper(last_name)) like :tag or upper(email) like :tag',
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));

$blogDataProvider = new CActiveDataProvider('Blog',array(
'criteria'=>array(
'condition'=>'upper(title) like :tag or upper(content) like :tag',
//'condition'=>'upper(title) like :tag',
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));

$forumDataProvider = new CActiveDataProvider('Forum',array(
'criteria'=>array(
'condition'=>'upper(title) like :tag or upper(content) like :tag or upper(category) like :tag',
//'condition'=>'upper(title) like :tag',
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));

$annconditionview = Persons::model()->get_view_condition('Announcement');
$announcementDataProvider = new CActiveDataProvider('Announcement',array(
'criteria'=>array(
'condition'=>'upper(title) like :tag or upper(content) like :tag '.$annconditionview,
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));

/*
$galleryDataProvider = new CActiveDataProvider('Gallery',array(
'criteria'=>array(
'condition'=>'upper(title) like :tag',
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));
*
*/

$pollconditionview = Persons::model()->get_view_condition('Polls');
$pollsDataProvider = new CActiveDataProvider('Polls',array(
'criteria'=>array(
'condition'=>'upper(title) like :tag or upper(content) like :tag '.$conditionforadmin.$pollconditionview,
//'condition'=>'upper(content) like :tag',
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));

$evtconditionview = Persons::model()->get_view_condition('Events');
$eventsDataProvider = new CActiveDataProvider('Events',array(
'criteria'=>array(
'condition'=>'upper(title) like :tag or upper(content) like :tag '.$evtconditionview,
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));

$job_tags = SystemParameters::model()->findByAttributes(array('name'=>'job_search_tag'))->value;
$job_tags_arr = explode(',', $job_tags);
//$tag_arr = explode(' ', $tag);
$tag_for_job = $tag;

$look_for_job = FALSE;
foreach($job_tags_arr as $v){
//if(in_array($v, $tag_arr)){
if($v == $tag){
$look_for_job = TRUE;
}
}
if($look_for_job){
$tag_for_job = '';
}

$jobsDataProvider = new CSqlDataProvider('Select *
FROM jobs
WHERE upper(job_title) LIKE "%'.strtoupper($tag_for_job).'%"',array(
'totalItemCount'=> Yii::app()->db->createCommand('Select count(*)
FROM jobs
WHERE upper(job_title) LIKE "%'.strtoupper($tag_for_job).'%"')->queryScalar(),
'pagination'=>false,
));


$this->render('search',array(
'tag'=>$tag,
'personDataProvider'=>$personDataProvider,
'blogDataProvider'=>$blogDataProvider,
'forumDataProvider'=>$forumDataProvider,
'announcementDataProvider'=>$announcementDataProvider,
//'galleryDataProvider'=>$galleryDataProvider,
'pollsDataProvider'=>$pollsDataProvider,
'eventsDataProvider'=>$eventsDataProvider,
'jobsDataProvider'=>$jobsDataProvider,
'look_for_job'=>$look_for_job
));
}

最佳答案

根据评论中的讨论,您必须按以下方式更改代码:在 Controller 中:

$personDataProvider = new CActiveDataProvider('Persons',array(
'criteria'=>array(
'condition'=>'company_name like :tag or upper(email) like :tag',
'params'=>array (
':tag' => strtoupper('%'.$tag.'%')
),
),
'pagination'=>false,
));

然后在模型中:注释掉不需要的条件,因为我们已经在条件部分检查了这两个字段。

$criteria->compare('party_id',$this->party_id,true);
// $criteria->compare('email',$this->email,true);
// $criteria->compare('company_name',$this->company_name);
$criteria->compare('middle_name',$this->middle_name,true);
$criteria->compare('dob_year',$this->dob_year);
$criteria->compare('dob_month',$this->dob_month);
$criteria->compare('dob_day',$this->dob_day);
$criteria->compare('nickname',$this->nickname,true);
$criteria->compare('country',$this->country,true);

关于php - 我被要求修复搜索功能中的错误。我在 yii 上不断收到 CDbException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21228346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com