1

in my yii based sample project i have a model named gateway and this model have a variable from DB with name $time that is a creation time for gateway that comes from php time() function
now i want to change this variable to readable form to show in view (not to save in DB) and for this i write a function setTime() for this and define a variable $readabletime
i didnt call function settime() in controller but in rules() of model i writ this line: array('time','setTime') but it dont work
how i canmake a function work in model????

this is my model

<?php


class UserGateway extends CActiveRecord
{
public $readabletime; 
/**
 * @return string the associated database table name
 */
public function tableName()
{
    return 'user_gateway';
}


public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('name, url, ip, time, userid, gatewaycategoryid', 'required'),
        array('time, status, userid, gatewaycategoryid, defaultgateway', 'numerical', 'integerOnly'=>true),
        array('name, url', 'length', 'max'=>120),
        array('ip', 'length', 'max'=>18),
        // The following rule is used by search().
        // @todo Please remove those attributes that should not be searched.
        array('id, name, url, ip, time, status, userid, gatewaycategoryid, defaultgateway', 'safe', 'on'=>'search'),
        array('time','setTime')
    );
}


public function setTime()
{
    $this->readabletime=date('m/d/Y H:i:s', $this->time);
}

}

and this is my view:

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-    button')); ?>

<div class="search-form" style="display:none">

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

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'UserAccountnumber-grid',

'dataProvider'=>$model->search(),

'filter'=>$model,
'columns'=>array(
    'name',
     'url',
    'ip',
    'readabletime',

    array(

        'class'=>'CButtonColumn',
        'buttons'=>array(
                'update' => array(
                'url'=>'Yii::app()->createUrl(\'User/UpdateGateway\',array(\'id\'=>$data[id]))'),
                'delete' => array(
                'url'=>'Yii::app()->createUrl(\'User/DeleteGateway\',array(\'id\'=>$data[id]))'

                        ),                            ),

                )
            )        


      )    



  );
  ?>

tnx :)

masoud
  • 33
  • 9

0 Answers0