edit values in app.yml by backend

北慕城南 提交于 2019-12-13 08:11:16

问题


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:


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.



来源:https://stackoverflow.com/questions/7299028/edit-values-in-app-yml-by-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!