dougan4663 2014-05-14 05:18 采纳率: 0%
浏览 22

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

I cant display value in repeated column names with inner join of two tables using yii. my view page is advance_search_detail.php and controller sitecontroller.php.I got the error 'Property "Job.Ltitle" is not defined'.

Controller is 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));
}

}

My view page is 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>   

Anybody help me?

  • 写回答

1条回答 默认 最新

  • douzou0073 2014-06-16 10:13
    关注

    Check Your two model relation first and then set alias to location table. Table Job has alias (t) and set table location alias (l). Like below

    $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';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教