Yii Framework Forum: Doubt about example - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Doubt about example chapter 6

#1 User is offline   Alexandre Carmo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 22-December 09
  • Location:Brazil - SP

Posted 05 January 2011 - 05:13 PM

Hello friends

I'm studying the chapter 6 and I have a doubt

I put this code in Issue class:
public function getStatusText()
        {
            $statusOptions=$this->statusOptions;
            return isset($statusOptions[$this->status_id]) ? $statusOptions[$this->status_id] : "unknow status ({$this->status_id})";
        }

        public function getTypeText()
        {
            $typeOptions=$this->typeOptions;
            return isset($typeOptions[$this->type_id]) ? $typeOptions[$this->type_id] : "unknow type ({$this->type_id})";
        }


and this in _view of Issue:
<b><?php echo CHtml::encode($data->getAttributeLabel('type_id')); ?>:</b>
	<?php echo CHtml::encode($data->getTypeText()); ?>
	<br />

	<b><?php echo CHtml::encode($data->getAttributeLabel('status_id')); ?>:</b>
	<?php echo CHtml::encode($data->getStatusText()); ?>
	<br />


This code change the display, after this code was diplay number, when I put this code display the text.
Please. Can anyone explain the code? I don't understand
0

#2 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 11 January 2011 - 01:03 AM

Both of these methods do basically the same thing (one for returning the text associated with the integer status value and one for returning the text associated with the integer type value). So, taking the one for status:

public function getStatusText()
{
		$statusOptions=$this->statusOptions;
		return isset($statusOptions[$this->status_id]) ? $statusOptions[$this->status_id] : "unknown status ({$this->status_id})";
}


$statusOptions will be an array that looks like:

array(0=>'Not Yet Started', 1=>'Started', 2=>'Finished')


And this method just returns the text that is associated with the key whose value happens to be the same as the status_id property of the instance.

So, if the issue instance happens to have its status_id property = 1, this method will return the value associated with

$statusOptions[1]


which is the value 'Started'.

Hope this helps.

0

#3 User is offline   Alexandre Carmo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 22-December 09
  • Location:Brazil - SP

Posted 15 January 2011 - 01:54 PM

thanks for help. I get it
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users