Forums / Developer / how to fetch class objects in php

how to fetch class objects in php

Author Message

ludo thomas

Friday 01 July 2005 5:12:38 am

hi,

I'm looking for the code that allows you to make an array whith objects of a class.I just have the class id:305

I tried this, but it seems not to work fine:

$liste = eZContentObject::fetchList( true, array( 'contentclass_id' => 305 ) )

do someone have an other solution?
thx.

Harry Oosterveen

Friday 01 July 2005 8:59:18 am

When using the fetchList function, you have to use a string instead of an array for specifying the condition:

$liste = eZContentObject::fetchList( true, 'contentclass_id = 305' )

ludo thomas

Friday 01 July 2005 9:42:02 am

thanks harry,

but in my case, it seems not to work.
in the admin I have a 'prod' class, ID='305'
in this class there is 6 objects.

I want to put this 6 objects in an array.

First I tried:

$list=& eZContentClass::fetch( 305 );

After I tried your solution:

$liste=eZContentObject::fetchList( true, 'contentclass_id = 305' );

I receive more than 100 objects. why? I have empty the trash..

Help please..

perrin aybara

Saturday 02 July 2005 1:20:12 am

http://ez.no/community/forum/developer/how_to_fetch_objects_in_php_on_specified_attributes

Bruce Morrison

Saturday 02 July 2005 7:16:36 pm

I think you'll find the answers here http://pubsvn.ez.no/doxygen/classeZContentObject.html#a24 and here http://pubsvn.ez.no/doxygen/classeZPersistentObject.html#a9

$liste = eZContentObject::fetchList( true, array( 'contentclass_id' => 305 ) )

Should do the trick, however if you may need to add additional conditions. What you are after is all the CURRENT PUBLISHED objects of this class right?

$liste = eZContentObject::fetchList( true, 
  array( 'contentclass_id' => 305,
         'status'          =>  EZ_CONTENT_OBJECT_STATUS_PUBLISHED) 
);

Should get you this.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

ludo thomas

Monday 04 July 2005 1:02:13 am

YESSSS!!!

Thanks a lot bruce, that's a good job!
It was exactly what I needed for my newsletter,
I hope I could help You in the future..