mopabootstrap bundle and symfony2 issue - symfony

I am using this mopabootstrap bundle, followed all of the instructions. I am getting the following error:
An exception has been thrown during the compilation of a template ("Unable to find file "#MopaBootstrapBundle/Resources/bootstrap/js/bootstrap-transition.js".") in "MopaBootstrapBundle::base.html.twig".
I found the thread here that seems to have an answer to my issue as well, but i tried it and it still gives me the same error. How can I fix this?

If you are using the latest version of MopaBootstrap, and Symfony 2.1 or 2.2, it seems that the twitter/bootstrap files aren't correctly installed and symlinked.
Maybe you have missed the composer.json part:
{
"scripts": {
"post-install-cmd": [
"Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap"
],
"post-update-cmd": [
"Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap"
]
}
}
from the MopaBootstrap doc
Those commands create the symlink from the vendors folder: /vendor/twitter/bootstrap
to the MopaBootstrap folder:
/vendor/mopa/bootstrap-bundle/Mopa/BootstrapBundle/Resources/bootstrap
Be sure to also install twitter/bootstrap in your composer.json:
{
"require": {
"mopa/bootstrap-bundle": "dev-master",
"twitter/bootstrap": "dev-master"
}
}

Related

Symfony 3.4 : generate bundle : ClassNotFoundException: Attempted to load class "MyVendorFOSUserBundle" from namespace "MyVendorFOSUserBundle"

Hello every body I'm doing inheritance from FOSUserBundle to override some controllers, but At first step when I was creating a simple bundle I found an issue:
bin/console genrate:bundle
Are you planning on sharing this bundle across multiple applications? [no]:
Bundle name: MyVendorFOSUserBundle
Target Directory [src/]: src/MyVendor/
Configuration format (annotation, yml, xml, php) [annotation]:
Bundle generation
> Generating a sample bundle skeleton into app/../src/MyVendor/MyVendorFOSUserBundle
created ./app/../src/MyVendor/MyVendorFOSUserBundle/
created ./app/../src/MyVendor/MyVendorFOSUserBundle/MyVendorFOSUserBundle.php
created ./app/../src/MyVendor/MyVendorFOSUserBundle/Controller/
created ./app/../src/MyVendor/MyVendorFOSUserBundle/Controller/DefaultController.php
created ./app/../tests/MyVendorFOSUserBundle/Controller/
created ./app/../tests/MyVendorFOSUserBundle/Controller/DefaultControllerTest.php
created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/views/Default/
created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/views/Default/index.html.twig
created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/config/
created ./app/../src/MyVendor/MyVendorFOSUserBundle/Resources/config/services.yml
> Checking that the bundle is autoloaded
FAILED
> Enabling the bundle inside app/AppKernel.php
updated ./app/AppKernel.php
OK
> Importing the bundle's routes from the app/config/routing.yml file
updated ./app/config/routing.yml
OK
> Importing the bundle's services.yml from the app/config/config.yml file
updated ./app/config/config.yml
OK
The command was not able to configure everything automatically.
You'll need to make the following changes manually.
- Edit the composer.json file and register the bundle
namespace in the "autoload" section:
At first solution I tried to modify composer.json :*
"autoload": {
"psr-4": {
"": "src/" //modif
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
Does someone have any idea about that
Open composer.json file.
Change this:
"autoload": { "psr-4": { "AppBundle\\": "src/AppBundle" },
to:
"autoload": { "psr-4": { "": "src/" },
Run this command: composer dumpautoload Now composer will generate new autoload.php file
Run command: php bin/console server:run everything works file.
Finally, I found the solution:
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"MyVendorFOSUserBundle\\": "src/MyVendor/MyVendorFOSUserBundle" //Line added
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
Don't forget to run:
composer dumpautoload

Symfony Generate new Bundle Failed to auto update autoload

I use Symfony Version 2.8. I get the following error when generating a new bundle.
I generate a new bundle using this command:
php bin/console generate:bundle --namespace=FrontBundle --no-interaction
Then the console show me this results
Bundle generation
Generating a sample bundle skeleton into C:\xampp\htdocs\TRC\app/../src/FrontBundle
created .\app/../src/FrontBundle/
created .\app/../src/FrontBundle/FrontBundle.php
created .\app/../src/FrontBundle/Controller/
created .\app/../src/FrontBundle/Controller/DefaultController.php
created .\app/../tests/FrontBundle/Controller/
created .\app/../tests/FrontBundle/Controller/DefaultControllerTest.php
created .\app/../src/FrontBundle/Resources/views/Default/
created .\app/../src/FrontBundle/Resources/views/Default/index.html.twig
created .\app/../src/FrontBundle/Resources/config/
created .\app/../src/FrontBundle/Resources/config/services.yml
Checking that the bundle is autoloaded
FAILED
Enabling the bundle inside C:\xampp\htdocs\TRC\app\AppKernel.php
updated .\app\AppKernel.php
OK
Importing the bundle's routes from the C:\xampp\htdocs\TRC\app\config\routing.yml file
updated .\app/config/routing.yml
OK
Importing the bundle's services.yml from the C:\xampp\htdocs\TRC\app\config\config.yml file
updated .\app/config/config.yml
OK
The command was not able to configure everything automatically.
You'll need to make the following changes manually.
Edit the composer.json file and register the bundle
namespace in the "autoload" section:
Process finished with exit code 0 at 17:19:48.
Execution time: 719 ms.
Then I add a line to Composer.Json in autoload section:
#...
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"FrontBundle\\": "src/FrontBundle"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"autoload-dev": {
"files": [
"vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
]
},
#.........
Finally, I use again the console to dump-autoload and when I refresh the page I get the same error.
I have tried to clear cache and force browser to refresh.
"psr-4": {
"AppBundle\\": "src/AppBundle",
"FrontBundle\\": "src/FrontBundle"
},
Or better:
"psr-4": {
"": "src/"
}

Do I need to append every generated bundle to composer.json manually?

I've started to learn Symfony and I am following some tutorials where there is nothing about this:
When I create a new project with symfony installer and run composer install and then php app/console server:start I can open that project in my browser.
BUT! When I create a new bundle with command php app/console generate:bundle I get this error message:
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "BlogBundle" from namespace "BlogBundle".
Did you forget a "use" statement for another namespace? in /home/user/Symfony/myapp/app/AppKernel.php:19
And then I need to go to my composer.json file and append my new generated bundle after AppBundle like this
{
"name": "user/myapp",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"BlogBundle\\": "src/BlogBundle" // <-- this is the new appended one
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
..........
And then when I try to start the server again it works and it shows Hello world in my browser.
So the question is do I have to do this every time (append new generated bundle in composer.json file)?
Yes. This is the reason, why you usually have an namespace above that. Some abbreviation of your name or company for example. This way you only add that namespace for the src folder and all bundles are "found" automatically.
Example:
{
...
"autoload": {
"psr-4": {
"Acme\\": "src"
},
}
...
}
Now of course your bundles need to use that namespace, eg.:
namespace Acme\BlogBundle;
class BlogBundle {
}

Including a Symfony bundle from a subtree : how to expand autoload path?

I'm using a bundle from a subtree, so I can't modify the structure nor the placement of it. I currently am trying to get it included in autoloading process, and am failing miserably with the "class not found" error message.
Currently, my project tree (made with Symfony 3.2) is :
|- app
|- src
|- MyappBundle
|- external
|- Author
|-UserBundle
|- Controller
|- [...]
|- AuthorUserBundle.php
AuthorUserBundle.php contains :
namespace Author\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AuthorUserBundle extends Bundle
{
}
To include this bundle, I added in app/AppKernel.php :
new Author\UserBundle\AuthorUserBundle(),
I also added to app/autoload.php, before AnnotationRegistry::registerLoader :
$loader->add('Author',__DIR__.'/../src/external');
I don't master the namespaces imbrications, especially regarding the depth of call, but I tried many variations in autoload.php (like '/../src/external/Author') or AppKernel.php (Author\UserBundle\AuthorUserBundle\AuthorUserBundle()) ending all with the same error message "Class not found".
What did I miss ?
Sorry for the newbie question, I tried alone first, thank you for your time.
P.S. : the external directory can't be removed, the git subtree process doesn't allow to operate in a non empty directory.
You shouldn't use git subtree to include 3rd party code. Add a composer.json to your AuthorUserBundle with all needed autoloading and dependencies. A minimal example (replace ^3.0 with ^2.7 if you still use Symfony 2.7/2.8):
{
"name": "author/user-bundle",
"license": "proprietary",
"type": "library",
"require": {
"symfony/framework-bundle": "^3.0"
},
"autoload": {
"psr-4": {
"Author\\UserBundle\\": ""
},
}
}
And require it in your main project as private repository. Please add git tags to and follow semantic versioning.
Assuming your bundle is then called author/user-bundle (composer name), add the following to your projects composer.json:
{
"require": {
"author/user-bundle": "^1.0"
},
"repositories": [
{
"type": "vcs",
"url": "git#git.example.author/user-bundle.git"
}
]
}
Edit 1: added composer.json for AuthorUserBundle repository.
I would give a try to addPsr4 method instead
$loader->addPsr4('Author\\UserBundle\\', __DIR__.'/../src/external/Author/UserBundle');

Wrap PHPWord on bundle

I just want to use PHPWord for Symfony 2. But Im new on Symfony 2.
I paste PHPWord source into my util folder bundle but there is an error loading autoloader class from PHPWord...
Question is simple, How can I "wrap" code (in this case PHPWord) in to bundle? or someway I can use it.
Any solution?
Thanks for answering, that gives me some light. Altough, This doen't work for me.
I download composer.phar and I edit my composer.json as you say: adding in my require region "phpword/phpword": "0.6.2" and creating new repository phpword...
Doesn't work, I run "php composer.phar" command but It doesn't download anything...
Any tutorial or tip to make this work?
Thank you
composer require phpoffice/phpword dev-master did the work for me.
It should download and place install PhpOffice\PHPWord under the vendor folder in your Symfony2 installation (besides modifying your composer.json automatically).
In the controller you are about to use PhpWord:
use PhpOffice\PhpWord\PhpWord;
And inside the action, you can create a new instance as follows:
$doc = new PhpWord();
You shouldn't be copying the source code yourself. Use composer to install PHPWord.
Since PHPWord doesn't use composer (yet), you'll need to define a repository in your composer.json:
{
"require": {
"phpword/phpword": "0.6.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "0.6.2",
"dist": {
"url": "http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=phpword&DownloadId=138035&FileTime=129545976016270000&Build=19692",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
Than you'll be able to use PHPWord in your Symfony project (any PHP project in fact):
$word = new PHPWord();
$writer = new PHPWord_Writer_Word2007($word);
$writer->save('test.doc');
Update: I just realized the URL to download changes with time. It'd be better to replace it with something that doesn't change (if possible, otherwise host it somewhere yourself).
As the URL changes, you can use the github repository if you've no problem with the dev version :
{
"require": {
"phpword/phpword": "dev"
},
"repositories": [
{
"type": "package",
"package": {
"name": "phpword/phpword",
"version": "dev",
"dist": {
"url": "https://github.com/PHPOffice/PHPWord/archive/develop.zip",
"type": "zip"
},
"autoload": {
"classmap": ["."]
}
}
}
]
}
You can use this simple bundle as wrapper for PhpWord:
https://packagist.org/packages/ggggino/wordbundle

Resources