I try to add an exeption when i a page not found, 404.
So i add this is ocnfig fos_rest :
# exception:
# codes:
# 'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
# 'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
# messages:
# 'Acme\HelloBundle\Exception\MyExceptionWithASafeMessage': true
But i have this error :
FOSRestBundle exception mapper: Could not load class 'Acme\HelloBundle\Exception\MyExceptionWithASafeMessage' or the class does not extend from '\Exception'. Most probably this is a configuration problem.
Since the namespace is acme it looks like you copied some demo tutorial code and the bundle doesn't exist.
You need to create your OWN exception class extending \Exception and pass its namespace there in the yml .
Related
I installed package composer require georgo/wsdl-creator.
The path to file I wanted to use is: vendor/georgo/wsdl-creator/src/WSDL/WSDLCreator.php
Inside this file it has namespace and class:
namespace WSDL;
class WSDLCreator
{
...
vendor/georgo/wsdl-creator/composer.josn has following code:
"autoload": {
"psr-0": {
"WSDL\\": "src/",
In my controller I used that class: use WSDL\WSDLCreator;
Then I wanted to use it public function createWSDL(WSDLCreator $WSDLCreator){...}
Then exception happened:
Cannot autowire argument $WSDLCreator of
"App\Controller\SOAPController::createWSDL()": it references class
"WSDL\WSDLCreator" but no such service exists.
I tried to modify that composer.json with additional "WSDL" since there is "WSDL" folder after "src":
"WSDL\\": "src/WSDL"
After clearing the cache multiple times the same exception happened.
Please help.
I added record to services.yaml
WSDL\WSDLCreator:
autowire: true
and it works now but generated obvious problems because third party packages aren't services and they has no type hints in constructors and in this case WSDLCreator is not even a bundle.
To use this package I had to just create a new object new WSDLCreator() in my method.
I'm trying to add the Assets dependencies to a TwigExtension however I'm ending up with :
Cannot autowire service "App\Twig\AppExtension": argument "$urlPackage" of method "__construct()" references class "Symfony\Component\Asset\UrlPackage" but no such service exists.
So this is basically what I'm doing :
use Symfony\Component\Asset\UrlPackage;
...
protected $urlPackage;
public function __construct(UrlPackage $urlPackage)
{
$this->urlPackage = $urlPackage;
}
....
$url = $this->urlPackage->getUrl("build/assets/images/svg/notification.svg");
And of course I've checked weather or not the package is existing :
/var/www/fromton # bin/console debug:container | grep assets
Symfony\Component\Asset\Packages alias for "assets.packages"
assets._default_package Symfony\Component\Asset\PathPackage
assets._version__default Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy
assets.context Symfony\Component\Asset\Context\RequestStackContext
assets.empty_package Symfony\Component\Asset\Package
assets.empty_version_strategy Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy
assets.json_manifest_version_strategy Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy
assets.packages Symfony\Component\Asset\Packages
assets.path_package Symfony\Component\Asset\PathPackage
assets.static_version_strategy Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy
assets.url_package Symfony\Component\Asset\UrlPackage
console.command.assets_install Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand
twig.extension.assets Symfony\Bridge\Twig\Extension\AssetExtension
What the heck is wrong? Shall I do something in services.yml too?
Shall I do something in services.yml too?
Yes, you need to define a new service alias completing the autowiring based on its FQCN:
services:
# ...
Symfony\Component\Asset\UrlPackage: '#assets.url_package'
How can I log errors to file log in SilverStripe 4?
I mean all errors causing 'Internal server error' info from SS
In SilverStripe it was :
SS_Log::add_writer(new SS_LogFileWriter('/var/log/silverstripe/errors.log'), SS_Log::ERR);
Documentation says that I need to do something like:
SilverStripe\Core\Injector\Injector:
Psr\Log\LoggerInterface:
calls:
LogFileHandler: [ pushHandler, [ %$LogFileHandler ] ]
LogFileHandler:
class: Monolog\Handler\StreamHandler
constructor:
- "../silverstripe.log"
- "info"
I try this but cannot get this to work :(
Try to add to your .env file (https://docs.silverstripe.org/en/4/getting_started/environment_management/) such string:
SS_ERROR_LOG = "silverstripe.log"
To create a custom log try:
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
Then later:
$logger = new Logger("my_name");
$logger->pushHandler(new StreamHandler('./silverstripe-custom.log', Logger::INFO));
$logger->info('hi there');
You should find silverstripe-custom.log in the project root.
I'm trying to get started with Symfony2 and I'm getting stuck on the "create your first page" tutorial : http://symfony.com/doc/current/book/page_creation.html
I created the controller file (copy-pasted from tutorial) as E:\Web\project\src\AppBundle\Controller\LuckyController.php :
<?php
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class LuckyController
{
/**
* #Route("/lucky/number")
*/
public function numberAction()
{
$number = rand(0, 100);
return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}
I didn't make any change to any other file.
When I go to the URL 127.0.0.1/project/web/app_dev.php/lucky/controller (127.0.0.1 is the virtual host for E:\Web) I keep getting the error "No route found for "GET /lucky/controller"".
404 Not Found - NotFoundHttpException
1 linked Exception:
[2/2] NotFoundHttpException: No route found for "GET /lucky/controller/"
[1/2] ResourceNotFoundException:
If I remove the "/web" from the URL, 127.0.0.1/project/app_dev.php/lucky/controller, I get a 404 error.
I'm pretty sure the error comes from the folder structure since the files are unmodified. Similar issue was reported here but none of these suggestions solved my error.
Just figured out that the URL should be 127.0.0.1/project/web/app_dev.php/lucky/number (and not controller). Problem solved.
Be careful, your route is /lucky/number not /lucky/controller.
So, you have to try with 127.0.0.1/project/web/app_dev.php/lucky/number
I'm getting following exception in my app/config/config.yml file:
ScannerException while scanning for the next token we had this found
character #(64) that cannot start any token
The line that causes exception:- { resource: #BazaBlogBundle/Resources/config/config.yml }
I think it's compatibility problem. I'm following tutorial for Symfony version 2.0 and I'm using 2.16. Any thoughts?
I think you are missing the double quotes :
- { resource: "#BazaBlogBundle/Resources/config/config.yml" }