dongqiu8375 2011-03-08 19: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 20: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 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。