dev-master
9999999-devSymfony 2 Back URL Annotation
MIT
The Requires
- php >=5.3.0
- symfony/framework-bundle 2.*
- doctrine/common >=2.1
by Yevhen Shyshkin
annotation redirect
Symfony 2 Back URL Annotation
This bundle allows to manage automatic redirects according to URL parameters. To do this you should use special annotation @BackUrl for controller class or controller action., (*1)
To process redirect you should specify parameter name which contains redirect URL. In controller action code you can trigger back URL redirect in desired place, and redirect will be performed after processing of controller action., (*2)
If URL doesn't contain back URL parameters, there won't be performed any additional actions., (*3)
Note: Annotation for controller action has higher priority than annotation for controller class., (*4)
Add bundle name to "require" section in composer.json:
"ys-tools/back-url-bundle": "dev-master"
, (*5)
Update composer packages:
composer update
, (*6)
Register bundle in kernel (defaults - file app\AppKernel.php, method registerBundles):
new YsTools\BackUrlBundle\YsToolsBackUrlBundle(),
, (*7)
This annotation will redirect user to URL specified in parameter "redirect" after processing of listAction controller action., (*8)
``` php use Symfony\Bundle\FrameworkBundle\Controller\Controller; use YsTools\BackUrlBundle\Annotation\BackUrl;, (*9)
class BlogController extends Controller { /** * @BackUrl("redirect") */ public function postAction() { ... BackUrl::triggerRedirect(); ... } }, (*10)
#### Controller Class Annotation This annotation will redirect user to URL specified in parameter "back_to" after processing of controller action which triggers back URL redirect. ``` php use Symfony\Bundle\FrameworkBundle\Controller\Controller; use YsTools\BackUrlBundle\Annotation\BackUrl; /** * @BackUrl("back_to") */ class BlogController extends Controller { ... public function listAction() { ... } ... public function postAction() { ... BackUrl::triggerRedirect(); ... } ... }
This annotation will save back URL from parameter "href" in Session object and will perform redirect when user triggers back URL redirect. Back URL will be stored in Session object until back URL redirect will be performed., (*11)
``` php use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use YsTools\BackUrlBundle\Annotation\BackUrl;, (*12)
class BlogController extends Controller { /** * @BackUrl("href", useSession=true) */ public function postAction(Request $request) { // form initialization..., (*13)
if ($request->isMethod('POST')) { $form->bind($request); if ($form->isValid()) { // save data to DB... BackUrl::triggerRedirect(); return $this->redirect($this->generateUrl('blog_list')); } } return $this->render( 'AcmeBlogBundle:Blog:post.html.twig', array('form' => $form->createView()) ); }
}, (*14)
Symfony 2 Back URL Annotation
MIT
annotation redirect