Overriding GroupAdmin class - php

I try to override my SonataUserBundle GroupAdmin Class, like that :
namespace Application\Sonata\UserBundle\Admin\Model;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\UserBundle\Admin\Model\GroupAdmin as MyGroupAdmin;
class GroupAdmin extends MyGroupAdmin
{
...
}
And add parameters in my config.yml file :
parameters:
sonata.user.admin.group.class: Application\Sonata\UserBundle\Admin\Model\GroupAdmin
But when I try to view my form I have that exception:
Attempted to load class "GroupAdmin" from namespace "Application\Sonata\UserBundle\Admin\Model".
Did you forget a "use" statement for e.g. "Sonata\UserBundle\Admin\Document\GroupAdmin", "Sonata\UserBundle\Admin\Entity\GroupAdmin" or "Sonata\UserBundle\Admin\Model\GroupAdmin"?
My kernel :
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new AppBundle\AppBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
new Sonata\FormatterBundle\SonataFormatterBundle(),
new Sonata\NewsBundle\SonataNewsBundle(),
new Sonata\MediaBundle\SonataMediaBundle(),
new Sonata\IntlBundle\SonataIntlBundle(),
new Sonata\ClassificationBundle\SonataClassificationBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Application\Sonata\NewsBundle\ApplicationSonataNewsBundle(),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
new Application\Sonata\ClassificationBundle\ApplicationSonataClassificationBundle(),
);
This is 6:00 and I can't find the error. Plz help

It definitely is not a problem with the class declaration or the error would contain 'The file was found but the class was not in it'.
You most likely have a typo in the name of the file

Related

Symfony is not able to register a bundle

I have a bundle in symproject/src/MyAppBundle/src/Bundle
This folder contains MyAppBundle.php:
<?php
namespace MyCompany\Action\Provider\MyAppBundle\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MyAppBundle extends Bundle
{
}
Then I register it in App/Appkernel.php:
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new MyCompany\Action\Provider\MyAppBundle\Bundle\MyAppbundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
if ('dev' === $this->getEnvironment()) {
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
}
}
return $bundles;
}
The site won't work at all after doing this. The log says:
PHP Fatal error: Uncaught Error: Class
'MyCompany\Action\Provider\MyAppProvider\Bundle\MyAppBundle' not
found in /var/www/html/symproject/app/AppKernel.php:20\nStack
trace:\n#0
/var/www/html/symproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(494):
AppKernel->registerBundles()\n#1
/var/www/html/symproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(134):
Symfony\Component\HttpKernel\Kernel->initializeBundles()\n#2
/var/www/html/symproject/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(197):
Symfony\Component\HttpKernel\Kernel->boot()\n#3
/var/www/html/symproject/web/app.php(19):
Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))\n#4
{main}\n thrown in /var/www/html/symproject/app/AppKernel.php on line
20
You've placed bundle class to
symproject/src/MyAppBundle/src/Bundle
folder, but namespace is
MyCompany\Action\Provider\MyAppBundle\Bundle
It should be like namespace
App\MyAppBundle\Bundle
and moved to folder
symproject/src/MyAppBundle/Bundle
Or you should change autoload section of your composer.json file to use different class loading.
https://getcomposer.org/doc/01-basic-usage.md#autoloading

Symfony error: Class 'Symfony\Component\HttpKernel\Kernel' not found

After upgrading from Symfony 3.1 to 3.2 I get this error message :
Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not
found in /var/www/html/HeliosBlog/app/AppKernel.php on line 6
Here's what my app/autoload.php looks like:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
if (!$loader = #include __DIR__.'/../vendor/autoload.php') {
$message = <<< EOF
EOF;
if (PHP_SAPI === 'cli') {
$message = strip_tags($message);
}
die($message);
}
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
Here's what my app_dev.php file looks like:
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'fe80::1', '::1')) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require __DIR__.'/../app/autoload.php';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
And here's what my AppKernel.php looks like:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Helios\BlogBundle\HeliosBlogBundle(),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new Helios\UserBundle\HeliosUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
new FOS\ElasticaBundle\FOSElasticaBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Helios\ManagerBundle\HeliosManagerBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
//new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(),
new Oneup\UploaderBundle\OneupUploaderBundle(),
new Gregwar\CaptchaBundle\GregwarCaptchaBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
$bundles[] = new CoreSphere\ConsoleBundle\CoreSphereConsoleBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
Already tried removing the vendor folder and doing a composer install.
Any ideas?
I was able to solve it by simply adding
require_once __DIR__.'/autoload.php';
to app/console before
require_once __DIR__ . '/AppKernel.php';`
Ran into the same error. Found that the bootstrap.php.cache was unaware of the Kernel class.
This happened due the Sensio Distibution bundle having an update.
For this I posted an issue which can be found here:
https://github.com/sensiolabs/SensioDistributionBundle/issues/302
I hope this helps others as well.
I had this issue while running composer update, because it was still using app/console (probably outdated) instead of the new bin/console.
I fixed this issue by:
removing app/console file.
creating a var/ folder in my project root directory - see this answer for explanation.
I run into this problem as well while updating my project from Symfony 2.x (can't remember whether it was 2.7 or 2.8) to 3.2. In turn out that the problem was caused by the app/console file. I believe the problem is caused by the way I created the project ages ago.
To solve this problem, I copied the app/console file from another project which I successfully upgraded to 3.2. I am not sure whether there will be some other problems down the line, but at least I got rid of this error.
The discussion that prompted me to make this change is https://github.com/symfony/symfony/issues/16713

dompdf in symfony only works in dev envirenment

I use the dompdf-bundle (slik/dompdf-bundle) in my symfony2-project (2.6.*) for the generation of pdf out of html. This works fine in my dev envirenment (MAMP) in dev (app_dev.php) and prod-mode.
In the prod envirenment I get an error with the exactly same data (DB) an code (GIT). So I checked the configuration of the server (PHP-version). Funny: When I run the prod-envirenment with app_dev.php the generation works fine!!! Where is the different between the app.php and the app_dev.php?
The error I get:
Error message in german
My AppKernel.php:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new GaertnerhuusBundle\GaertnerhuusBundle(),
new GaertnerhuusAdminBundle\GaertnerhuusAdminBundle(),
new Slik\DompdfBundle\SlikDompdfBundle()
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
I solved my issue with a work-around. I replaced the dompdf bundle with the mpdf bundle. This one works fine for my solution:
https://github.com/tasmanianfox/MpdfPortBundle

My site doesnt work in live mode

I have actually a problem with my site when i want to turn it in live mode. I have this error:
Fatal error: Class
'Lexik\Bundle\TranslationBundle\LexikTranslationBundle' not found in
/home/maisonka/www/app/AppKernel.php on line 27
but I don't understand because my bundle lexik is in my vendor and appKernel.php looks like:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Kayser\PlatformBundle\KayserPlatformBundle(),
new Liip\ImagineBundle\LiipImagineBundle(),
new Sonata\IntlBundle\SonataIntlBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Lexik\Bundle\TranslationBundle\LexikTranslationBundle(),
);
I found what was my problem, I just deleted this line: "new Lexik\Bundle\TranslationBundle\LexikTranslationBundle()," and now everything works perfectly.

Error loading swift mailer in symfony

Am using swift mailer to send emails for my symfony application.But it is throwing the error:
There is no extension able to load the configuration for "transport". I am getting the error when it loads the configuration file the app is crashed. Please help me to know how can I exact define it's configuration parameters.
My app/config.yml is like:
swiftmailer:
transport: gmail
username: 'myemail#example.com'
password: 'Mypassword'
I have also checked app/Appkernel.php swiftmailer bundle is already registered:
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Acme\SuperbAppBundle\AcmeSuperbAppBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
Am using the following code to send email:
$message = \Swift_Message::newInstance()
->setSubject('Hello Email') // we configure the title
->setFrom('myemail#example.com') // we configure the sender
->setTo('someone#example.com') // we configure the recipient
->setBody("Hello User");
$send = $this->get('mailer')->send($message); // then we send the message.
Your indentation is wrong. It should be like..
swiftmailer:
transport: gmail
username: 'myemail#example.com'
password: 'Mypassword'

Categories