Ok, vì vậy tôi không có một giải pháp đầy đủ nhưng một chút hơn nơi để tìm kiếm một :)
Bạn có thể chỉ nâng bốc hàng (dịch vụ) cho mặt hàng khuôn mẫu trong app/config/config.yml
framework:
esi: { enabled: true }
#translator: { fallback: %locale% }
secret: %secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: %kernel.debug%
form: true
csrf_protection: true
validation: { enable_annotations: true }
templating:
engines:
- twig
loaders: [moby.loader]
default_locale: %locale%
trust_proxy_headers: false
session: ~
Sau đó xác định các dịch vụ nạp được đề cập:
services:
moby.loader:
class: Acme\AppBundle\Twig\Loader\MobyFilesystemLoader
arguments: ["@templating.locator", "@service_container"]
Sau đó xác định dịch vụ nạp của bạn lớp:
namespace Acme\AppBundle\Twig\Loader;
use Symfony\Bundle\FrameworkBundle\Templating\Loader\FilesystemLoader;
use Symfony\Component\Templating\Storage\FileStorage;
class MobyFilesystemLoader extends FilesystemLoader
{
protected $container;
public function __construct($templatePathPatterns, $container)
{
parent::__construct($templatePathPatterns);
$this->container = $container;
}
public function load(\Symfony\Component\Templating\TemplateReferenceInterface $template)
{
// Here you can filter what you actually want to change from html
// to mob format
// ->get('controller') returns the name of a controller
// ->get('name') returns the name of the template
if($template->get('bundle') == 'AcmeAppBundle')
{
$request = $this->container->get('request');
$format = $this->isMobile($request) ? 'mob' : 'html';
$template->set('format', $format);
}
try {
$file = $this->locator->locate($template);
} catch (\InvalidArgumentException $e) {
return false;
}
return new FileStorage($file);
}
/**
* Implement your check to see if request is made from mobile platform
*/
private function isMobile($request)
{
return true;
}
}
Như bạn có thể thấy đây không phải là giải pháp đầy đủ, nhưng tôi hy vọng điều này, ít nhất, hướng bạn đi đúng hướng.
EDIT: Chỉ cần phát hiện ra rằng có một bó với khả năng phát hiện điện thoại di động, với động cơ cành lá tùy chỉnh mà làm cho tập tin mẫu tùy thuộc vào một thiết bị gửi yêu cầu ZenstruckMobileBundle, mặc dù tôi không bao giờ sử dụng nó như vậy ... :)
Nguồn
2012-08-13 17:36:07
Tôi không chắc chắn giải pháp sẽ liên quan đến khuôn khổ. Bạn đã kiểm tra http://www.hand-interactive.com/resources/detect-mobile-php.htm#download chưa? – FMaz008