I always do the following in the view. ($data is passed from the
controller)
<h1> Some Title </H1>
<?php
if (empty($data)) {
echo "No entries/posts/products/etc. found"
} else {
// Create the table here, list the posts/products/entries/etc,
whatever...
}
?>
. I doubt there are better ways... The elements one you proposed looks
a bit cleaner in the sourcecode I guess, but when you split up your
views over all kind of elements, it'll get unmanageble in my opinion
and harder to make quick changes...
On 11 okt, 20:04, DigitalDude <[email protected]> wrote:
> Hey,
>
> today I was wondering about how I could deal with an index-view where
> no data is available. The main point I'm trying to demonstrate here is
> the following scenario:
>
> In index-views, commonly we have let's say a table where the data we
> grab from our tables is displayed. But when a user just registered for
> your app, there won't be any data to display. In this case, there
> would be an EMPTY table and that looks really bad in my opinion.
>
> I think in this case it would be better if there would be NO TABLE and
> instead, there should be a message like "Currently you have no entries
> in this category. Add some data by clicking this link...!"
>
> So what I mean is, there should be a check if there is any data to
> display, and if NOT, a message like the one above should be printed.
>
> But what's the best practice for that? I figured out two
> possibilities, but I'm not quite sure if it's really the perfect
> way...
>
> 1.
> We could use two elements; one where the message is displayed, and one
> where the data is displayed (for example in a table or so...)
> I would do the following check:
>
> if($somedata) {
> echo $this->renderElement('DataShowElement');} else {
>
> echo $this->renderElement('EmptyDataMessage');
>
> }
>
> 2.
> pretty much the same, but without elements so in the view there would
> be a check if the data-variable has any elements and the table would
> only be shown when the data-array has any entries, otherwise there
> would be only the message.
>
> What is the correct way to do this? Are there any other techniques to
> deal with this kind of problem?
>
> Regards,
>
> DD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---