通过后端编辑 app.yml 中的值

发布于 2024-12-03 00:56:24 字数 717 浏览 0 评论 0原文

public function executeShow(sfWebRequest $request)
{
  $this->category = $this->getRoute()->getObject();

  $this->pager = new sfDoctrinePager(
    'JobeetJob',
    sfConfig::get('app_max_jobs_on_category')
  );
  $this->pager->setQuery($this->category->getActiveJobsQuery());
  $this->pager->setPage($request->getParameter('page', 1));
  $this->pager->init();
}

sfConfig::get('app_max_jobs_on_category')

# apps/frontend/config/app.yml
all:
  active_days:          30
  max_jobs_on_homepage: 10
  max_jobs_on_category: 20

我怎样才能让管理员可以在后端编辑这个值(max_jobs_on_category)? 每个用户是否只能为自己进行编辑?

public function executeShow(sfWebRequest $request)
{
  $this->category = $this->getRoute()->getObject();

  $this->pager = new sfDoctrinePager(
    'JobeetJob',
    sfConfig::get('app_max_jobs_on_category')
  );
  $this->pager->setQuery($this->category->getActiveJobsQuery());
  $this->pager->setPage($request->getParameter('page', 1));
  $this->pager->init();
}

sfConfig::get('app_max_jobs_on_category')

# apps/frontend/config/app.yml
all:
  active_days:          30
  max_jobs_on_homepage: 10
  max_jobs_on_category: 20

how can i make that admin can edit this values (max_jobs_on_category) in backend?
And is possible that each user can this edit only for himself?

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

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

发布评论

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

评论(1

小巷里的女流氓 2024-12-10 00:56:24

我认为你最好为这些设置创建一个数据库模型。然后,您可以在过滤器中查询数据库(请参阅 http://www.symfony-project.org/gentle-introduction/1_4/en/06-Inside-the-Controller-Layer#chapter_06_sub_the_filter_chain)。

例如:

AppSetting:
  columns:
    id:
      type: integer(4)
      primary: true
    name:
      type: string(100)
      notnull: true
    value:
      type: string(100)

过滤器代码示例:

$settings = Doctrine_Core::getTable('AppSetting')->fetchAll();
foreach ($settings as $setting) {
  sfConfig::set($setting->getName(), $setting->getValue());
}

当然,每个请求加载所有这些设置是一些额外的开销,您可以根据需要查询它们:

Doctrine_Core::getTable('AppSetting')->findOneByName('some_setting')->getValue();

或者您可以更进一步,为它们创建一些序列化缓存。但最后,如果您需要从网络界面编辑它们,我会选择数据库解决方案。

I think you are better creating a database model for those settings. You could then query the database in a filter for example (see http://www.symfony-project.org/gentle-introduction/1_4/en/06-Inside-the-Controller-Layer#chapter_06_sub_the_filter_chain).

For example:

AppSetting:
  columns:
    id:
      type: integer(4)
      primary: true
    name:
      type: string(100)
      notnull: true
    value:
      type: string(100)

Example filter code:

$settings = Doctrine_Core::getTable('AppSetting')->fetchAll();
foreach ($settings as $setting) {
  sfConfig::set($setting->getName(), $setting->getValue());
}

Ofcourse this is some extra overhead to load all these settings every request, you could just query them as you need them:

Doctrine_Core::getTable('AppSetting')->findOneByName('some_setting')->getValue();

Or you could go even further and create some serialized cache for them. But in the end, I'd go for a database solution if you need to edit them from a web interface.

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