What is the best way to implement the MobileVersion of an WebApplication Developed in Symfony 1.4? I searched on google but had no success.
Don't really know how to start or if there is any standard to follow. Should I just implement different templates or an entirely different application (like frontend/backend).
My first quess is to implement a filter which will act like a onRequest listener and if user-agent is mobile to redirect to the mobile app. But I think in this way (with different apps) it's very difficult to migrate from mobile to browser version and vice-versa.
That's almost exactly the way it is defined on the symfony website.
Check the article: How to create an optimized version of your website for the iPhone in symfony 1.1, specially this part:
// config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// ...
$this->dispatcher->connect('request.filter_parameters', array($this, 'filterRequestParameters'));
}
public function filterRequestParameters(sfEvent $event, $parameters)
{
$request = $event->getSubject();
if (preg_match('#Mobile/.+Safari#i', $request->getHttpHeader('User-Agent')))
{
$request->setRequestFormat('iphone');
}
return $parameters;
}
}
Now, every request from an iPhone will use *Success.iphone.php templates instead of *Success.php templates.
As you say, it will be harder to switch from an environment to an other. Like viewing the full website from an iPhone. For this, you should handle it using session with a parameter like ?doaction=read_on_site
then, set a cookie and the check inside the filterRequestParameters
.
Edit:
It will be more easier to use a filter instead. Easy access to the request and the response
<?php
class iPhoneFilter extends sfFilter
{
public function execute ($filterChain)
{
// get the cool stuff
$context = $this->getContext();
$request = $context->getRequest();
$response = $context->getResponse();
if ($this->isFirstCall())
{
$cookies = $response->getCookies();
if (preg_match('#Mobile/.+Safari#i', $request->getHttpHeader('User-Agent'))
&& ! isset($cookies['doaction']))
{
$request->setRequestFormat('iphone');
}
}
// execute next filter
$filterChain->execute();
}
}