Forums / Setup & design / Can not fetch my "home made" objects...

Can not fetch my "home made" objects...

Author Message

Milad P

Tuesday 19 December 2006 8:05:04 am

Hi,

I created a simple class which only contains a textinput. Then i created a folder with several of my new class objects. My problem is when i try to fetch information from that node, i got nothing back. It works if i put some other objects (like article, link, folder etc.) but not my new class?

Why? it seems very strange?

This is the code that i use to fetch my objects. I can not find any problems with the code.


        {def $children_count=fetch('content', 'list_count', hash('parent_node_id', 12785 ) ) }
        {def $children=fetch('content', 'list', hash('parent_node_id', 12785) ) }

        {do}
                {def $nr = rand(0,$children_count)}
        {/do while($children[$nr].object.data_map.name.content|null())}
        <b>{"Did you know that"|i18n('chsmisc')}</b>
        {$children[$nr].object.data_map.name.content}



Claudia Kosny

Wednesday 20 December 2006 1:18:49 am

Hi Milad

Is the problem caused by the fetch functions or by the loop? Do you get any messages in debug output?

You cannot use {def ... in a loop as you can define a variable only once in a template. So you either {undef $nr} in the loop again or you put {def $nr = 0} (or so) before the loop and use {set $nr = ...} in the loop.

Check whether $children_count and $children contain anything. Check whether $children[$nr].object.data_map.name exists (maybe you have a typo in your class definition).

Regarding the loop itself: if you just want to have a random node where the attribute name contains something, it might be more efficient to limit the fetch to these noses using the attribute filter and to use the limit and offset parameter to fetch just one node.

For fetching random content see here:
http://ez.no/community/forum/setup_design/how_to_fetch_random_content_3_8/re_how_to_fetch_random_content_3_8

Claudia

Milad P

Wednesday 20 December 2006 5:58:38 am

Hi again,

The problem is in the fetch line. $children and $children_count contains nothing. $children returns a empty array and $children_count = 0.

//Milad

Claudia Kosny

Wednesday 20 December 2006 1:02:34 pm

Hi Milad

Do you see your custom objects in the admin view under the specified parent node?
If not, you have the wrong parent node.
If yes, I think there is something wrong with either the visibility, the permissions or the translations of your custom objects. So add the following parameters to your fetch parameters:

'ignore_visibility' => true(),
'limitation' => array(),
'only_translated' => false()

Clear the cache and try again. Does that help?

Claudia

Milad P

Thursday 21 December 2006 1:18:57 am

Thank you for your advise. It seems that i have forgot to set the proper permissions for my new object. Problem solved.