通过后端编辑 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
我怎样才能让管理员可以在后端编辑这个值(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你最好为这些设置创建一个数据库模型。然后,您可以在过滤器中查询数据库(请参阅 http://www.symfony-project.org/gentle-introduction/1_4/en/06-Inside-the-Controller-Layer#chapter_06_sub_the_filter_chain)。
例如:
过滤器代码示例:
当然,每个请求加载所有这些设置是一些额外的开销,您可以根据需要查询它们:
或者您可以更进一步,为它们创建一些序列化缓存。但最后,如果您需要从网络界面编辑它们,我会选择数据库解决方案。
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:
Example filter code:
Ofcourse this is some extra overhead to load all these settings every request, you could just query them as you need them:
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.