cache:pool:clear
command. This command will delete all data from the project storage directory. By default, Symfony comes with 3 cache clearers. They arecache.global_clearer
cache.system_clearer
cache.app_clearer
namespace FreeTimeLearn\DemoBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class FreeTimeLearnDemoBundle extends Bundle {
}
public function registerBundles() {
$bundles = array(
// ...
// register your bundle
new FreeTimeLearn\DemoBundle\FreeTimeLearnDemoBundle(),
);
return $bundles;
}
php bin/console generate:bundle --namespace = FreeTimeLearn/DemoBundle
SensioFrameworkExtraBundle
and JMSSecurityExtraBundle
which provide better support for annotations. Using these bundles you can use annotations for controller configuration, routing, cache, security, template, etc. $session = new Session();
$session->start();
$session->set('user_id', 200);
$session->get('user_id');
$session->remove('user_id');
$request->get("_route"); //OR with Twig {{ app.request.attributes.get('_route') }}
;
).Directives are used to control Modules and divided into simple directives and block directives.php -r "readfile('https://symfony.com/installer');" > symphony
sudo mkdir -p /usr/local/bin
sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony
$request->query->get('paraemeter_name')
method is used to get the request parameters in symfony2. registerBundles()
method is used to enable bundles in Symfony. createFromGlobals()
:use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
__construct()
call :$request = new Request(
$_GET,
$_POST,
[],
$_COOKIE,
$_FILES,
$_SERVER
);
$_POST;
$_GET ($request->query->get('name'));
$_COOKIE;
(see below);
$_FILES;
$_SERVER;
$_SERVER ($request->headers->get('User-Agent'))
.getPathInfo()
method :// for a request to http://example.com/blog/index.php/post/hello-world
// the path info is "/post/hello-world"
$request->getPathInfo();
$request = Request::create(
'/hello-world',
'GET',
['name' => 'Fabien']
);
use App\Http\SpecialRequest;
use Symfony\Component\HttpFoundation\Request;
Request::setFactory(function (
array $query = [],
array $request = [],
array $attributes = [],
array $cookies = [],
array $files = [],
array $server = [],
$content = null
) {
return new SpecialRequest(
$query,
$request,
$attributes,
$cookies,
$files,
$server,
$content
);
});
$request = Request::createFromGlobals();
use Symfony\Component\HttpFoundation\Response;
$response = new Response(
'Content',
Response::HTTP_OK,
['content-type' => 'text/html']
);
$response->setContent('Hello World');
// the headers public attribute is a ResponseHeaderBag
$response->headers->set('Content-Type', 'text/plain');
$response->setStatusCode(Response::HTTP_NOT_FOUND);
setCharset()
method :$response->setCharset('ISO-8859-1');
$response->prepare($request);
send()
:$response->send();
public function indexAction()
{
return $this->render('user/index.html.twig', [ ]);
}
use Symfony\Component\Form\Extension\Core\Type\EmailType;
$builder->add('token', EmailType::class, array(
'data' => 'abcdef', ));
Use Symfony\Component\Validator\Constraints as Assert;
class Student {
/**
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
protected $email;
}
if ($request->isXmlHttpRequest()) {
// Ajax request
} else {
// Normal request
}
public function sessionAction(SessionInterface $session)
{
// store an attribute for reuse during a later user request
$session->set('user_id', 5);
// get the attribute set by another controller in another request
$user_id = $session->get('user_id');
}​
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController {
public function indexAction() {
return new ViewModel();
}
}
safe
" mode to assist those who don't want to be exposed to content to which they might object. The RFC 8674
specification defines a way for user agents to ask for safe content to a server.preferSafeContent();
setContentSafe();
if ($request->preferSafeContent()) {
$response = new Response($alternativeContent);
// this informs the user we respected their preferences
$response->setContentSafe();
return $response;