Why is symfony2 not copying my bundle over? - php

My appKernel.php looks like this:
<?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 Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Blogger\BlogBundle\BloggerBlogBundle(),
);
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;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
My autoload.php looks like:
<?php
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
'Sensio' => __DIR__.'/../vendor/bundles',
'JMS' => __DIR__.'/../vendor/bundles',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
'Monolog' => __DIR__.'/../vendor/monolog/src',
'Assetic' => __DIR__.'/../vendor/assetic/src',
'Metadata' => __DIR__.'/../vendor/metadata/src',
));
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
));
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
}
$loader->registerNamespaceFallbacks(array(
__DIR__.'/../src',
));
$loader->register();
AnnotationRegistry::registerLoader(function($class) use ($loader) {
$loader->loadClass($class);
return class_exists($class, false);
});
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
// Swiftmailer needs a special autoloader to allow
// the lazy loading of the init file (which is expensive)
require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php';
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php');
When I do:
php app/console assets:install web
I get the following:
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Symfony\Bundle\WebProfilerBundle into web/bundles/webprofiler
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
Why is my BloggerBlogBundle not getting copied over?

Note: As OP's answer is short and doesn't really go into too much detail, here's a more in-depth answer for future readers, so hopefully you don't have to do as much digging as I did! :)
It seems that we're following the exact same tutorial and have the exact same issue, and as the answer above isn't very descriptive and I had to do a little digging myself, here's exactly what's wrong.
Step 1
Your src/Blogger/BlogBundle needs to have, in the /resources folder, a public/css folder. So you need to place your CSS files as follows:
src/Blogger/BlogBundle/resources/public/css/<stylesheet>.css
Create the /public/css folder if it doesn't exist (it didn't exist for me).
Step 2
You need to run the assetic management tool to have a symlink created in /web automatically for you so these can be accessed.
php app/console assets:install web
You now will notice that if you open (using windows explorer / nautilus on linux) your dev directory and find the /web folder, that /web/bundles/bloggerblog/css/<stylesheet>.css has been created automatically for you!
You can now access your CSS files in your code using:
<link href="{{ asset('/bundles/bloggerblog/css/<stylesheet>.css') }}" type="text/css" rel="stylesheet" />
Note: '.css' is replaced with screen 'screen.css' for this tutorial
...and that should be it!

I have the the exact same problem with the original question, where assets are not copied over from Resources folder of bundles to web/bundles after running 'php app/console assets:install web' so what i did was running this command 'php app/console cache:clear --env=prod' and that fixed it. As you can see that you are dealing with prod assets or installing assets to prod environment in web directory, so clear cach for prod is reasonable. So do this:
1) $ php app/console cache:clear --env=prod
2) $ php app/console assets:install web
OR $ php app/console assets:install web --symlink
3) $ php app/console assetic:dump --env=prod (If you use built in Assetic, it will dump/combine css to one big one in /web/css as opposed to /web/bundles)
everything goes in place after that. you get all assets in your /web/bundles and assetic dump in /web/css and all of these are for prod env.

Just had this problem, ensure that the BlahBundle.php is located in the same directory as the Resources directory

I've had this issue today with Symfony3.3.13 and the problem was the public directory was actually capitalised Public, which seems to break the install script. Changing the name and it worked immediately.

Related

Assets not loading on symfony

I try to load css and js files from my symfony project and for all files I have 404.
So, I try like this :
<link href="{{ asset('css/css-theme/bootstrap.min.css') }}" rel="stylesheet">
I mention that I create the install of web :
php bin/console assets:install web --symlink
As result I have :
Trying to install assets as absolute symbolic links.
Bundle Methode/Error
FrameworkBundle absolute symlink
[OK] All assets were successfully installed
What I'm doing wrong ? Please help me. Thx in advance
Since Symfony 2.8 Assetic Bundle is not embebbed with this. You must install first your assetic bundle :
install with composer
composer require symfony/assetic-bundle
declare bundle in you appKernel
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
);
// ...
}
}
declare config in your config.yml
# app/config/config.yml
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
You also need to dump assets via command:
php bin/console assets:dump
This physically writes all of the asset files you need for your environment. The big disadvantage is that you need to run this each time you update an asset
You can use "watch" command so that assets are regenerated automatically as they change.
php bin/console assetic:watch
More on assets management process here:
Symfony asset Documentation
Edit
Correct command for dump is.
php bin/console assetic:dump
You may also need to install "assetic" bundle via composer. With a command.
composer require symfony/assetic-bundle
And add it to your AppKernel:
public function registerBundles()
{
$bundles = array(
// ...
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
);
// ...
}

Symfony 2 install third party bundle manually

My Internet conexion is useless to install a symphony 2 dependency with composer as far as I can say. Is there a way to install a third party bundle manually? I have been looking in Google and I did not find any useful thing so far. About my connection issue, I started this thread to try and find a solution to install within this connection. here I am trying to find clues to a solution to install manually.
Regards
1 Create under vendor directory the path for bundle :
/*like mycompany*/ /*like product-bundle*/ /*like MyCompany*/
vendor/yourbundlenamespace/your-bundle-name-bundle/YourBundleNameSpace/
2 Go to in the new path and put the content of budle (or clone from github).
3* #deprecated
Load the reference path on autoload, so go to in
vendor/composer/autoload_namespaces.php
and put in the array
'YourBundleNameSpace\\YourBundleNameBundle' => array($vendorDir . '/yourbundlenamespace/your-bundle-name-bundle');
4 Register bundle: go to in
app/AppKernel.php
and put in the array $bundles the new bundle:
```
public function registerBundles()
{
$bundles = array(
//...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
//...
// this is our bundle :)
$bundles[] = new YourBundleNameSpace\YourBundleNameBundle\YourBundleNameBundle();
}
```
UPDATE
Point 3: this method is not performance because when update via composer is overwrite, instead, you should do:
-go to on app/autoload.php
and put following code after $loader definition
```
//add customs classes
$loader->add('YourBundleNameSpace\\YourBundleNameBundle','vendor//yourbundlenamespace/your-bundle-name-bundle');
```

ClassNotFoundException Symfony

I'm trying to make my website live but keep getting the same error...I've tried looking everywhere and using everyone solution with no luck.
Error
ClassNotFoundException: Attempted to load class "DestinationAppBundle" from namespace "Destination\AppBundle" in /home/dcms/public/html/dcms/apha/app/AppKernel.php line 19. Do you need to "use" it from another namespace?
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 Destination\AppBundle\DestinationAppBundle(),
new Destination\Auth\HashInterfaceBundle\DestinationHashInterfaceBundle(),
);
File Structure
src
Destination
AppBundle
Any ideas?
first: check if the file src\Destination\AppBundle\DestinationAppBundle.php does exist
second: open DestinationAppBundle.php and chek if the namespace is Destination\AppBundle
third: check if the classname declaration is the same as the filename (in your case : DestinationAppBundle)
Update composer.json like this:
"psr-4": {
"AppBundle\\": "src/AppBundle",
"UserBundle\\": "src/UserBundle"
},
After edit composer.json YOU MUST RUN composer dump-autoload
Verify in AppKernel.php the use of this class DestinationAppBundle
And the namespace in the class DestinationAppBundle
What is the namespace in your DestinationAppBundle.php ?
It should be :
<?php
namespace Destination\AppBundle;
If you are sure the namespace and service definition are right you can try:
Upgrade Symfony version. I had an strange issue with Symfony 2.8.11, new services added gave me a ClassNotFoundException. Upgrading to 2.8.17 solved it.
Try remove app/cache/* contents
Check if you are using a pre-generated boostrap cached file without the "--no-dev" option (composer dump-autoload --optimize --no-dev --classmap-authoritative) and launch command again.
Symfony uses PSR autoload.
You need to configure autoload in the composer.json file:
"autoload": {
"psr-4": {
"": "src/"
},
This will include all files and folders under the \src folder

Symfony 2 no command for generating doctrine crud

i`m trying to generate CRUD for some entities in Symfony 2, apparently the
generate:doctrine:crud command is unavailable.
[InvalidArgumentException]
Command "generate:doctrine:crud" is not defined.
also , in the list for available commands, I only get one command.
generate
generate:doctrine:entities Generates entity classes and method stubs from your mapping information
is there a bundle or something in the configuration missing, or what is the cause for not having this functionality.
Addition:
The doctrine:generate:crud command is provided by the SensioGeneratorBundle
Please also make sure you have the bundle available and registered in your app/AppKernel.php like this:
class AppKernel extends Kernel
{
public function registerBundles()
{
// ...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
// ...
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
// ...
}
As in my example the command is also normally only available in the dev environment. Therefore ...
php app/console --env=prod doctrine:generate:crud
.. or any other configuration that uses production enviroment won't work.
doctrine:generate:crud is the command you should use
You can see a list of commands using php app/console list

Doctrine 2 - problems with "Getting Started XML-Edition" - generating database schema

Having never touched Doctrine before (either 1 or 2), I am following this tutorial for Doctrine 2.
I'm at the point where I use the command line to generate the database schema. This is the cli-config.php file, as per the tutorial:
<?php
$cliConfig = new Doctrine\Common\Cli\Configuration();
$cliConfig->setAttribute('em', $entityManager);
When I run it though, I just get an error:
Fatal error: require(): Failed opening required 'Doctrine\Common\Cli\Configuration.php'
Because that class referenced by the cli-config.php file doesn't exist. I've also tried blanking the cli-config.php file, which of course doesn't work either - says that "The helper "em" is not defined."
I'm using version 2.0.0BETA3. I know that this is a beta version, so they could have changed some files around, but I can't find that class anywhere.
Any ideas on how to get it working?
The docs in the XML Getting Started are outdated in this regard. Please see the Tools section in the manual on how to configure the CLI Tool:
http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html
All the rest still works as described. I will update this part asap.
Assuming you installed Doctrine using pear
$ sudo pear install pear.doctrine-project.org/doctrineORM
which will install the three 'Doctrine 2' packages: DoctrineCommon, DoctrineDBAL, and DoctrineORM. On Ubuntu, these packages will be located in /usr/share/php/Doctrine, and the doctrine command line utility, will be installed into /usr/bin.
With this setup, this is a version of cli-config.php you can use (note: DIR should have two underscores before and after it. For some reason they didn't display).
<?php
require ‘Doctrine/ORM/Tools/Setup.php’;
// Setup Autoloader (1)
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
require_once 'Doctrine/Common/ClassLoader.php';
$classLoader = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$connectionOptions = array(
'driver' => 'pdo_mysql',
'dbname' => 'bugs',
'user' => 'bugs',
'password' => 'xyzabc',
'host' => 'localhost' );
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));

Categories