PHP code example of yavin / symfony-init-controller

1. Go to this page and download the library: Download yavin/symfony-init-controller library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yavin / symfony-init-controller example snippets


class SampleController extends Controller implements InitControllerInterface
{
    protected $page;

    public function init(Request $request)
    {
        if ($request->get('redirect') == 1) {
            return $this->redirect('http://example.com');
        }

       $this->page = $request->get('page');
    }

    public function indexAction()
    {
        //some action code
    }
}

   namespace Acme\DemoBundle\Controller;

   use Symfony\Bundle\FrameworkBundle\Controller\Controller;
   use Symfony\Component\HttpFoundation\Request;
   use Yavin\Symfony\Controller\InitControllerInterface;

   class SampleController extends Controller implements InitControllerInterface
   {
       protected $page;

       public function init(Request $request)
       {
           //init method could return response, for example redirect
           if ($request->get('redirect') == 1) {
               return $this->redirect('http://example.com');
           }

           $this->page = $request->get('page');
       }

       public function indexAction()
       {
           //...
       }

       public function otherAction()
       {
           //...
       }
   }