I have a situation in one of my controllers that should only be accessed via AJAX, I have the following code.
if (!$request->isXmlHttpRequest()) {
$response = new Response();
$response->setContent('AJAX requests only!');
return $response;
}
When I am testing this gives me an issue because the request hasn't actually been made via AJAX. This then breaks my tests every time. How should I go about working around this?
My Ideas:
Anyone else have any other ideas or tips that I am missing to get one of the above to work?
The “.env” file Starting from v1.28 , the .env file is placed at the base of the project directory. Project directory can be explicitly defined with the --file option or COMPOSE_FILE environment variable. Otherwise, it is the current working directory where the docker compose command is executed ( v1.28 ).
Open project properties by right clicking on the project in the solution explorer and select Properties. This will open properties page. Click on Debug tab and you will see Environment Variables as shown below. You may change the value as per your need.
Of course in Icode4food's case, it's better to use Matt's solution, but here is how to find the current environment:
$this->container->getParameter(‘kernel.environment’)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With