duanjue6575
2011-09-04 11:55 阅读 46
已采纳

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

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongyijing2353 dongyijing2353 2011-09-04 13:10

    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.

    点赞 评论 复制链接分享

相关推荐