dongqiu8375 2011-03-08 11:57
浏览 33
已采纳

Kohana / PHP - 管理通知消息

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');
}

展开全部

  • 写回答

1条回答 默认 最新

  • dongzhuo3376 2011-03-08 12:00
    关注

    You should only use the notice class in your controller really. Assign data to it by inspecting model results, then read from it and assign that output to your view directly. Don't use the class right in your view.

    This will make your code more reusable, easier to read and easier to manage.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 mes系统扫码追溯功能
  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部