PHP code example of cscfa / twig_ui_bundle

1. Go to this page and download the library: Download cscfa/twig_ui_bundle 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/ */

    

cscfa / twig_ui_bundle example snippets


use Cscfa\Bundle\TwigUIBundle\Modules\AbstractTopLevelModule;
// or
use Cscfa\Bundle\TwigUIBundle\Modules\AbstractStepModule;

// Get a registed object. By default, only the User instance is given by the controller
$environment->getObjectsContainer()->getObject($alias);

// Get the current controller name
$environment->getControllerInfo()->getControllerName();

// Get the current controller method
$environment->getControllerInfo()->getMethodName();

$twigRequest = new TwigRequest();
$twigRequest->setTwigPath("AcmeBundle:Default:index.html.twig");
$twigRequest->setArguments(array(
    "fooArgument" => "foo",
    "barArgument" => "bar",
));
$twigRequest->remArgument("barArgument");
$twigRequest->hasArgument("fooArgument");

// Note the constructor allow to pass the template path and the arguments.
$twigRequest->addChildRequest(
    new TwigRequest(
        "AcmeBundle:Default:index.html.twig",
        array("fooArgument" => "foo")
    ),
    "ChildAliasName"
);

class AcmeController extends ModulableController
{
    public function processAction()
    {
        return $this->processModule(
            'CscfaTwigUIBundle:test:controllerResult.html.twig',
            __METHOD__,
            'cscfa_twig_ui.test.main'
        );
    }
}

class AcmeController extends ModulableController
{
    public function processAction(Request $request)
    {
        $builder = new EnvironmentOptionBuilder();
        $builder->addOption(
            $builder::OBJECT_CONTAINER_OBJECT, 
            array($request, "request")
        );
        
        return $this->processModule(
            'CscfaTwigUIBundle:test:controllerResult.html.twig',
            __METHOD__,
            'cscfa_twig_ui.test.main',
            $builder
        );
    }
}

class module extends AbstractTopLevelModule
{
    public function render(EnvironmentContainer $environment)
    {
        $environment->getObjectsContainer()
            ->getObject("request");
    }
}

// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            [...]
            new Cscfa\Bundle\TwigUIBundle\CscfaTwigUIBundle(),
        );
        
        [...]
    }
}