mig*_*rso 0 php mobile symfony1
我正在symfony项目中创建移动版本,我正在使用此处描述的技术:http://symfony.com/blog/how-to-create-an-optimized-version-of-your-website-for-the -iPhone合的symfony-1-1
到目前为止它是有效的,但我有一个问题:我的大多数标准页面完全有效,用手机浏览,但symfony强迫我创建*Success.mobile.php模板...我希望symfony使用普通模板,如果它找不到.mobile.php.那可能吗?你会如何解决它?
如果该模板存在,则必须在渲染之前进行检查,如果不存在,则设置默认模板.这可以通过添加一个检查它的过滤器来完成.所以...
将此过滤器添加到lib /文件夹,例如/lib/filters/ViewFilter.class.php
<!-- /lib/filters/ViewFilter.class.php -->
class ViewFilter extends sfFilter{
public function execute($filterChain){
if ($this->isFirstCall()){
//get context
$context = $this->getContext();
//get module name
$module = $context->getModuleName();
//get action name
$action = $context->getActionName();
//get template file name for this request
$templateFile = $action . "Success.mobile.php";
//set physical path of that template
$path = sfConfig::get('sf_app_module_dir').DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR."templates".DIRECTORY_SEPARATOR. $templateFile;
//check if exists
if(!file_exists($path))
//if is not, set html format to render the {$action}Success.php
$context->getRequest()->setRequestFormat('html');
}
$filterChain->execute();
}
}
Run Code Online (Sandbox Code Playgroud)
然后添加到您的filters.yml
<!-- /apps/frontend/config/filters.yml -->
rendering: ~
security: ~
# insert your own filters here
ViewFilter:
class: ViewFilter
cache: ~
execution: ~
Run Code Online (Sandbox Code Playgroud)
并且应该工作:)如果您不知道什么是过滤器及其功能,请参阅Symfony的过滤器指南以帮助您入门.
| 归档时间: |
|
| 查看次数: |
1197 次 |
| 最近记录: |