Search options. create_time and user_id...convert to timezone and username.

Dear all,

I am doing search in my index.php. Here is my code:

In _search.php


<div class="wide form">


<?php 

$form=$this->beginWidget('CActiveForm', array(

	'action'=>Yii::app()->createUrl($this->route),

	'method'=>'get',

)); ?>


	<div class="row">

		<?php echo $form->label($model,'name'); ?>

		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>256)); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'owner_id'); ?>

		<?php echo $form->textField($model,'owner_id'); ?>

	</div>


	<div class="row">

		<?php echo $form->label($model,'create_time'); ?>

		<?php echo $form->textField($model,'create_time'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Search'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- search-form -->

Is there a way to change owner_id to username?

And change create_time to timezone? For example, 1 week ago, 2 days ago…etc.

Or should I do this in my Model?


$criteria=new CDbCriteria;

		$criteria->compare('name',$this->name,true);

                $criteria->compare('owner_id',$this->owner_id,true);

		$criteria->compare('create_time',$this->create_time,true);

Thanks!

anyone…?

Hi,

using AR, you must declare the relation in your model




	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'user' => array(self::BELONGS_TO, 'User', 'user_id'), 

...

		);

	}



And in the search you can use somthing like this:




		$criteria=new CDbCriteria;

		$criteria->with = array( 'user');

		$criteria->compare( '"user".user_lastname', $this->user_search,true);

...



Then you can ask a name in your search form.