I've noticed this recently, from a clean install of Symfony2 and removed AcmeDemoBundle (from the AppKernel, routing_dev.yml etc.). I generate the bundle and noticed that the Target directory for the bundle has changed and every time I create a new bundle I have to manually put in the proper path to it. Seems to be a problem with the latest release of Symfony2.
Changed Target directory line during bundle creation:
Target directory [/var/www/html/Project/app/cache/dev/../src]:
The path that it use to point was:
Target directory [/var/www/html/Project/src]:
I am at a loss for what changed as I installed a clean build and did not alter any settings.
When I installed Symfony2 I used the following: (which is the same way I've used previously)
composer create-project symfony/framework-standard-edition Project #stable
php app/console generate:bundle (see last line)
Welcome to the Symfony2 bundle generator
Your application code must be written in bundles. This command helps
you generate them easily.
Each bundle is hosted under a namespace (like Acme/Bundle/BlogBundle).
The namespace should begin with a "vendor" name like your company name, your
project name, or your client name, followed by one or more optional category
sub-namespaces, and it should end with the bundle name itself
(which must have Bundle as a suffix).
See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more
details on bundle naming conventions.
Use / instead of \ for the namespace delimiter to avoid any problem.
Bundle namespace: Foo/FooBundle
In your code, a bundle is often referenced by its name. It can be the
concatenation of all namespace parts but it's really up to you to come
up with a unique name (a good practice is to start with the vendor name).
Based on the namespace, we suggest FooFooBundle.
Bundle name [FooFooBundle]:
The bundle can be generated anywhere. The suggested default directory uses
the standard conventions.
Target directory [/var/www/html/Project/app/cache/dev/../src]:
Fixed by updating composer:
composer self-update
Then creating a new project.
Related
The documentation says that there is file api/config/api_platform/resources.yaml where I can map entities using yml. But neither in the distribution nor when I install API-platform as a package I can't find this file. Creation of the directory and file manually doesn't help.
In the context of a Symfony 4 project, the file can be located at config/api_platform/resources.yaml. If it doesn't exist, simply create it.
You can also use several files in order to define your mappings:
config/api_platform/resources/entity1.yaml
config/api_platform/resources/entity2.yaml
I suggest to use separate files since it's simpler to maintain than one big file.
You'll have to configure these paths in the config/packages/api_platform.yaml file:
api_platform:
mapping:
paths: ['%kernel.project_dir%/config/api_platform/resources']
See Nek's answer for a complete example.
I find the documentation a little bit confusing about this, because in a Symfony project there's no api/ directory at the root of the project.
For one of a monitoring project I need to find out the class names available in a OSGI bundle (apache Karaf). I checked in the bundle and bundleContext class, but could not find any relevant methods to get the class names. Please help!!
PS - i can get the list of classes using bundle:class command. But i would like to get from the code.
EDIT - It is not 1 bundle for which i need to know, i want to run the code in any karaf environment to find all the bundles and also class names in those bundles.
You can simply do the same that apache karaf does See the source of the classes command:
https://github.com/apache/karaf/blob/master/bundle/core/src/main/java/org/apache/karaf/bundle/command/Classes.java
I am developing a Symfony2 web app that will be hosted on an Ubuntu server and want my directory structure to be:
/Symfony (with an app,bin and vendor folder in it)
/Site1
/Site2
This way site1 and site2 use the same Symfony framework. In /Site1 I want:
/web
and in there I want app.php and app_dev.php as well as /web/AppBundle with all of the bundle files. I already figured out that I need to change in app.php require_once DIR.'/../Symfony/app/AppKernel.php'; in 2 places as per http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html
When I generated the bundle I did get the message "Checking that the bundle is autoloaded: FAILED" and that I should "Edit the composer.json file and register the bundle namespace in the "autoload" section"
I added "AppBundle": "/web/AppBundle" to the composer.json autoload section and in cygwin I run "composer -n install" It starts with saying that it is loading composer repositories and then it says "Installing dependencies (including require-dev)" and never goes past that.
What can I do to register this bundle that is not in the standard folder so that autoload picks it up? I am just getting the fact that the class could not be found in AppKernel.php
Thanks.
It's simple. Just don't do it! Use symfony as it is intended with its default directory structure.
Great two projects. If you have common code, extract it to an extra bundle and install it in both projects via composer.
I am using PhpStorm for the Symfony project.
I've created new file in project type. I choose composer project and used symfony/framework to download composer.phar. After creating the project, I didn't find vendor file.
What am I doing wrong? Any tutorial to install Symfony in PhpStorm?
What I usually do is creating the project with the Symfony installer and without PhpStorm (like explained in the symfony doc).
Then, when it is correctly installed, open PhpStorm -> New Project from Existing Files -> locate your project folder.
Hope this helps.
I'm very new to symfony2 and I cannot find this info:
To register a bundle located in my vendor dir, how to determine the namespace and Bundle name for autoload.php & Appkernel.php?
For example, I have downloaded Luiggio's PHPExcel Bundle. I have place it in vendorDir/ExcelBundle/
Where content is:
namespace Liuggio\ExcelBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class LiuggioExcelBundle extends Bundle
{
}
What lines should I put in Appkernel and namespace.php?
This and this does not work:
new Liuggio\ExcelBundle\LiuggioExcelBundle()
//'Liuggio\\ExcelBundle' => array($vendorDir. '/PHPExcel'),
I cannot use composer or github repo at all, too many proxies and restrictions where I am.
You shouldn't place bundles in your vendor directory manually. Let Composer do this for you. Not only does Composer know where vendor libraries / bundles should be located, it also adds them to your autoload files and performs some other automated tasks.
To tell Composer which libraries are required, you should add them to your composer.json:
"require" : {
(...)
"liuggio/ExcelBundle": "~2.0"
},
Next, using the command line, run the composer update command:
$ php composer.phar update
(if you don't have a file composer.phar in your project directory, but you have Composer installed globally instead, use the following:)
$ composer update
This will tell Composer to download the required dependencies, update the autoload script, etc, all automatically. When it's finished, you're ready to go.
If you can't use Composer on your server, then run it locally before you upload your files (although I strongly recommend moving to a server that does allow you to use Composer).
The line you're trying to add to AppKernel.php is correct, however it only works after running Composer (or you'd indeed have to download the files and update the autoloader manually, but I'd strongly recommend against that).
Edit
If you really can't use Composer, do the following:
Place the files of ExcelBundle in the following directory:
vendor/liuggio/ExcelBundle/Liuggio/ExcelBundle
Your line in AppKernel.php was already correct.
Add this line to autoload_namespaces.php:
'Liuggio\\ExcelBundle' => array($vendorDir . '/liuggio/ExcelBundle'),
Last but not least, complain to your system administrator that he's making your work impossible with his stupid security measures.
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
in AppKernel should be working fine.
This is the namespace of the LuiggioExcelBundle class + the class name. Look how your bundles are loaded, its the same.
What's your error?
You say vendorDir/ExcelBundle/ but its vendor/ExcelBundle right?
And what do you mean by namespace.php? :o
https://github.com/liuggio/ExcelBundle ==> there readme is rly easy to understand, it should help you.
For your "proxies and restriction", composer is a powerful tool, I can help you to use it. Download this soft, the free version is enough http://www.frozenway.com/ (if you cant read french, the 1st input in the header is to translate the website, English is Anglais) With this, you wont have any ports restriction.