I'm developing custom web application - at the same time - I'm learning a lot.
I'm on the stage where I need some community tips.
I'd like to standarize errors/notifications management in my app so I'm using Notify module.
Let's say I have a module items
, in this module I got view() method.
First of all, I'm querying DB for specific item:
$item = ORM::factory('item', $id);
if( $item->loaded() )
{
return $item;
}
else
{
return Notice::msg('No items found', 'success');
}
then in my view:
<?php if( Notice::count() ) { ?>
<?php echo Notice::render(); ?>
<?php } else {
<?php echo $content ?>
} ?>
Now there's my question. Is it correct approach? Do you have any techniques worth copying?
Edit
According to Zombor's answer the following solution would be more elegant, isn't it?
Model:
$item = ORM::factory('item', $id);
if( !$item->loaded() )
{
return false;
}
else
{
return $item;
}
Controller:
if( !$model->method()->loaded() )
{
Notice::msg('No items found', 'success');
}