Martijn, hell of a response you did. I'm impressed with the concise and detailed explanation.
Couple of words though, I wasn't reporting an issue, because initially I wasn't quite sure if I am the one who's doing it wrong, hence my question for correction at the end of my previous post.
Secondly, something that doesn't work, to me resembles to a problem, like the issue in word that's why I so mouthful say that this is a problem.
Thirdly, of course it does return an array and not an object, but if that's not the intended behavior could you please post your working part to echoing $obj->link(); with a LIMIT of 1 since I am certain that it does not work either way, because the if conditional with the $limit parameter at the end of the function tries to take over, something that has been already executed differently.
and lastly, I don't see how removing the last if condition would break SQLite compatibility, I am familiar with most of the differences between MySQL and SQLite, but I must admit I'm very eager to learn it.
Please, be so kind again and give me a thorough explanation. My acknowledgements to you.
P.S. I tried it even on 0.6.0a with the default installation code, on the default layout and everything, just changed limit 5 to 1 and you guessed it, the non-object fatal error shows miraculously.
Update: It is working now.
Martijn, I see the problem was at my side, but I was misguided by the documentation in the Wiki here, so I can't take all the blame upon my shoulders, by this line above to be more precise.
The array produced by children() requires a foreach loop to present usable information.
No it doesn't. That is only valid when we set 'limit' to 2 or greater. With 'limit' set to 1 the error is produced from within a foreach loop of course.
So for clarification to other users as they don't deserve to go through the whole CMS framework files
When we want to echo a single result, or the last post in the articles case, don't use a foreach loop just set 'limit' => 1,
this is valid and works
<?php
$page_article = $this->find('/articles/');
$last_article = $page_article->children(array('limit'=>1, 'order'=>'page.created_on DESC')); ?>
<h2 class="post_title"><?php echo $last_article->link(); ?></h2>
<?php echo $last_article->content(); ?>
<?php if ($last_article->hasContent('extended')) echo $last_article->link('Continue Reading…'); ?>
P.S. I am submitting the change to the Wiki btw. Have a great day.
Last edited by tokolo (2010-09-10 16:56)