开发者

edit values in app.yml by backend

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
开发者_如何学JAVA  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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜