PHP code example of qafoolabs / no-framework-bundle
1. Go to this page and download the library: Download qafoolabs/no-framework-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/ */
qafoolabs / no-framework-bundle example snippets
$bundles = array(
// ...
new QafooLabs\Bundle\NoFrameworkBundle\QafooLabsNoFrameworkBundle(),
);
# src/Acme/DemoBundle/Controller/DefaultController.php
namespace Acme\DemoBundle\Controller;
class DefaultController
{
public function helloAction($name = 'Fabien')
{
return array('name' => $name);
}
}
# src/Acme/DemoBundle/Controller/DefaultController.php
namespace Acme\DemoBundle\Controller;
use QafooLabs\MVC\TemplateView;
class DefaultController
{
public function helloAction($name = 'Fabien')
{
return new TemplateView(
array('name' => $name),
'hallo', // AcmeDemoBundle:Default:hallo.html.twig instead of hello.html.twig
201,
array('X-Foo' => 'Bar')
);
}
}
# src/Acme/DemoBundle/View/Default/HelloView.php
namespace Acme\DemoBundle\View\Default;
class HelloView
{
public $name;
public function __construct($name)
{
$this->name = $name;
}
public function getReversedName()
{
return strrev($this->name);
}
}
# src/Acme/DemoBundle/Controller/HelloController.php
namespace Acme\DemoBundle\Controller;
class HelloController
{
public function helloAction($name)
{
return new HelloView($name);
}
}
# src/Acme/DemoBundle/Controller/DefaultController.php
namespace Acme\DemoBundle\Controller;
use QafooLabs\MVC\RedirectRoute;
class DefaultController
{
public function redirectAction()
{
return new RedirectRoute('hello', array(
'name' => 'Fabien'
));
}
}
# src/Acme/DemoBundle/Controller/DefaultController.php
namespace Acme\DemoBundle\Controller;
use QafooLabs\MVC\Headers;
use QafooLabs\MVC\Flash;
use Symfony\Component\HttpFoundation\Cookie;
class DefaultController
{
public function helloAction($name)
{
yield new Cookie('name', $name);
yield new Headers(['X-Hello' => $name]);
yield new Flash('warning', 'Hello ' . $name);
return ['name' => $name];
}
}
# src/Acme/DemoBundle/Controller/DefaultController.php
namespace Acme\DemoBundle\Controller;
use QafooLabs\MVC\TokenContext;
class DefaultController
{
public function redirectAction(TokenContext $context)
{
if ($context->hasToken()) {
$user = $context->getCurrentUser();
} else if ($context->hasAnonymousToken()) {
// do anon stuff
}
if ($context->isGranted('ROLE_ADMIN')) {
// do admin stuff
echo $context->getCurrentUserId();
echo $context->getCurrentUsername();
}
}
}
# src/Acme/DemoBundle/Controller/DefaultController.php
namespace Acme\DemoBundle\Controller;
use QafooLabs\MVC\FormRequest;
use QafooLabs\MVC\RedirectRoute;
class ProductController
{
private $repository;
public function __construct(ProductRepository $repository)
{
$this->repository;
}
public function editAction(FormRequest $formRequest, $id)
{
$product = $this->repository->find($id);
if (!$formRequest->handle(new ProductEditType(), $product)) {
return array('form' => $formRequest->createFormView(), 'entity' => $product);
}
$product = $formRequest->getValidData();
$this->repository->save($product);
return new RedirectRoute('Product.show', array('id' => $id));
}
}
public function indexAction(Session $session)
{
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.