Yii Framework Forum: incorrect documentation? - Yii Framework Forum

Jump to content

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

incorrect documentation? Rate Topic: -----

#1 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 744
  • Joined: 02-February 09

Posted 09 March 2010 - 09:03 AM

Looking at the class reference for 1.1 at the findAll() method. The documentation claims that the method returns an array. I then return the results of findAll() to a custom function and load the function as part of the data of activeDropDownList(). Now I get an error and I know why I get the error. Because findAll() returned an Object. :-[ Why is the documentation claiming that findAll() returns an array. Am I missing anything or misunderstanding anyting?

Cheers,
bettor
0

#2 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 09 March 2010 - 10:31 AM

View Postbettor, on 09 March 2010 - 09:03 AM, said:

Am I missing anything or misunderstanding anyting?


I think so, because findAll() certainly returns an array (both the CActiveRecord and CActiveFinder versions). What is your custom function doing?
0

#3 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 09 March 2010 - 11:48 AM

it returns an array of objects on success
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#4 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 744
  • Joined: 02-February 09

Posted 09 March 2010 - 11:49 AM

View Postjsoo, on 09 March 2010 - 10:31 AM, said:

I think so, because findAll() certainly returns an array (both the CActiveRecord and CActiveFinder versions). What is your custom function doing?


my custom function just returns the result of findAll()
0

#5 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 09 March 2010 - 12:03 PM

Are you running it through CHtml::listData() before passing it to your activeDropDownList?
0

#6 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 744
  • Joined: 02-February 09

Posted 09 March 2010 - 12:19 PM

View Postjsoo, on 09 March 2010 - 12:03 PM, said:

Are you running it through CHtml::listData() before passing it to your activeDropDownList?


Hi, yes I am and it's working...but it is not working without running it through listData() :)
0

#7 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 09 March 2010 - 12:35 PM

View Postbettor, on 09 March 2010 - 12:19 PM, said:

Hi, yes I am and it's working...but it is not working without running it through listData() :)


Right, just to clarify: findAll() returns an array of objects. CHtml::listData() returns an associative value=>text array (or an array of such arrays if $groupField is set). dropDownList doesn't know what to do with an array of objects. So, the documentation is correct :)
0

#8 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 744
  • Joined: 02-February 09

Posted 09 March 2010 - 03:38 PM

View Postjsoo, on 09 March 2010 - 12:35 PM, said:

Right, just to clarify: findAll() returns an array of objects. CHtml::listData() returns an associative value=>text array (or an array of such arrays if $groupField is set). dropDownList doesn't know what to do with an array of objects. So, the documentation is correct :)


brilliant. thanks for clarifying this.
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