如何添加“热门事件/最近更新”部分到使用 Symfony 1.4 构建的网站?

发布于 2024-12-19 04:37:50 字数 288 浏览 5 评论 0原文

我正在使用 symfony 1.4 开发一个网站。用户上传照片并将照片保存在数据库中。

现在在主页上,我有一些内容,我想要有一个部分显示最近上传的照片。我不确定这样做的最佳方法是什么。你能指出我正确的方向吗?

我能想到的唯一方法是让 $sf_content 保存主要内容(将来自应用程序/模块),并且对于最近的上传,让 layout.php 执行数据库访问+业务逻辑+渲染,但这会违反MVC,并且每次用户在网站中导航时都会涉及大量的数据库访问。

可以做得更好吗?

I'm developing a website with symfony 1.4. The users upload photos and the photos are saved in a database.

Now on the homepage, I have some content and I want to have a section that shows the recently uploaded photos. I'm not sure what is the best way of doing this. Could you please point me in right direction?

The only way I can think of is to have $sf_content hold the main content (which will come from the app/modules) and for recent uploads, have layout.php do database access+business logic+rendering but that will violate the MVC and will involve huge database access every time the user navigates in the website.

Can it be made better?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2024-12-26 04:37:50

您可以使用组件。

apps/yourapp/modules/yourmodule/actions/components.class.php

class yourmodulenameComponents extends sfComponents {


    public function executeRfoto() {

        $this->photos = Doctrine_Core::getTable('Photo') ->getRecentPhotos();

    }

模型中:

public function getRecentPhotos()
  {
    $q = $this->createQuery('a')
              ->addORDERBY('DESC');

    return $q->execute();
  }

在您的 apps/yourapp/modules/yourmodule/themplates/_rfoto.php 中

    foreach ($photos as $photo){
// Make some stuff
}

layout.php 或其他您想要放置照片的地方:

   <?php include_component('yourmodule' ,'rfoto')?>

You can use components.

apps/yourapp/modules/yourmodule/actions/components.class.php

class yourmodulenameComponents extends sfComponents {


    public function executeRfoto() {

        $this->photos = Doctrine_Core::getTable('Photo') ->getRecentPhotos();

    }

In model:

public function getRecentPhotos()
  {
    $q = $this->createQuery('a')
              ->addORDERBY('DESC');

    return $q->execute();
  }

in your apps/yourapp/modules/yourmodule/themplates/_rfoto.php

    foreach ($photos as $photo){
// Make some stuff
}

And In layout.php , or other place where you want to put your photo:

   <?php include_component('yourmodule' ,'rfoto')?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文