使用yii框架从内部联接的数据库中选择显示值

时间:2014-05-14 05:18:19

标签: php yii

我无法使用yii在具有两个表的内连接的重复列名中显示值。我的视图页面是advance_search_detail.php和controller sitecontroller.php。我收到了错误' Property" Job.Ltitle"没有定义'。

Controller是sitecontroller.php

public function actionadvance_search_result()
{
$title=$_GET['title'];
$experience=$_GET['experience'];
$location=$_GET['location'];
$category=$_GET['category'];
$salary_min=$_GET['salary_min'];
$salary_max=$_GET['salary_max'];

$criteria = new CDbCriteria();
$criteria->select = 't.title, location.title as  Ltitle,  t.key_skills, t.description, t.no_vacancy, t.experience, t.company_name, t.salary';
$criteria->join = 'INNER JOIN location ON t.location_id = location.id';
if($experience!="")
{
$criteria->addCondition("(title like '%$title%' or  key_skills like '%$title%') and   (experience like '%$experience%')");    
}
if($location!="")
{
   $criteria->addCondition("location_id like '%$location%'");
}

if($category!="")
{
   $criteria->addCondition("category_id like '%$category%'");
}
if($salary_min!="" && $salary_max!="")
    {
        $criteria->addCondition("salary >= '$salary_min' and salary <= '$salary_max'");
    }

$count=Job::model()->count($criteria);
$pages=new CPagination($count);
$pages->pageSize=2;
$pages->applyLimit($criteria);
$model=Job::model()->findAll($criteria);
$number_rec=count($model);
if($number_rec<=0)
{
  $this->render('search_result1',array('model' =>$model));
}
else
{
  $this->render('advance_search_result',array('model' =>$model,'pages' => $pages));
}

}

我的观看页面是advance_search_result.php

<div>
<div>
<h1>Search Results</h1>
<ul style="list-style:none; ">
<?php
  foreach($model as $models)  
  {
    $job_id=$models->id;
  ?>
   <li><p><?php //echo $models->title; ?>
      <?php echo CHtml::link($models->title, array('site/advance_search_detail', 'job_id'=>$job_id,'status'=>0)); ?></p>
      <p><?php echo CHtml::link($models->Ltitle); ?></p>
      <p><?php echo $models->company_name; ?></p>
      <p><?php echo $models->description; ?></p>
      <p>Keyskill:<?php echo $models->key_skills; ?><p>
  </li></br>
<?php
  }
 ?>
</ul>    
<p><?php $this->widget('CLinkPager', array('pages' => $pages)) ?></p>   

   

有人帮帮我吗?

1 个答案:

答案 0 :(得分:0)

首先检查您的两个模型关系,然后将别名设置为位置表。 表作业具有别名(t)并设置表位置别名(l)。如下所示

$criteria = new CDbCriteria();
$criteria->select = 't.title, l.title as  Ltitle,  t.key_skills, t.description, 
t.no_vacancy, t.experience,   t.company_name, t.salary';

$criteria->join = 'INNER JOIN location l ON t.location_id = l.id';