通过后端在app.yml中编辑值 [英] edit values in app.yml by backend

查看:242
本文介绍了通过后端在app.yml中编辑值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ ;

$ 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)?
每个用户是否可以只为自己编辑?

解决方案

我认为你更好地创建一个数据库这些设置的模型。然后,您可以在过滤器中查询数据库,例如(参见 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(); 

或者你可以更进一步,为他们创建一些序列化缓存。但是最终,如果您需要从Web界面进行编辑,我会去找一个数据库解决方案。


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?

解决方案

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.

这篇关于通过后端在app.yml中编辑值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆