Can we change Default directory name "Acme" to any other? - php

I just want to know can we change the Default directory structure i.e Bundle inside a Bundle like that and default Bundle directory Acme to something else.

Acme is just a dummy vendor name. Replace it with your own when creating your own bundles.
can we change the Default directory structure i.e Bundle inside a Bundle
What do you mean with 'bundle inside a bundle'? You want to create a AcmeDemoBundleFooBundle? No, that isn't possible.
As said in the comments. If you want to rename a bundle vendor, you need to do this manually. There is no script/command for that. (sidenote: The PHP grammar is much to flexible to write a good refactoring tool, that's why it don't exists or don't work)
You don't only have to rename the vendor name, you need to make sure all configuration is correct and uses the new vendor instead of Acme. This doc article is talking about removing bundles, but it can also be used as a checklist for savelly removing the bundle on a safe way.

Esy, delete your folder "Acme" with its content. Then though terminal call
php app/console generate:Bundle --namespace="Main\DefaultBundle
And you will get "Main" instead of "Acme"
Also you need clear appKenrel and other config files from your old configurations.

Related

How to use one module in two different application/project in yii2

I have module created in the basic project of yii2 and now i want to access or use that module another project/application of mine....
How can I achieve this.
please help me out here.
To use module in different apps there are 3 things you need.
The module must not be dependent on classes from core project. For any class that needs to be implemented by core project the module should define interface and depend on that interface instead of class itself.
The module should use different namespace than app and autoloader must know how to load classes from that namespace. (more about that later)
You have to add module in your config in same way you've added it in first project.
The points 1 and 3 are pretty much self-explaining. If are not sure how to add module in config see the yii2 guide.
Now back to the second point. While naive way of copying module over to second project would work it will turn maintaining the module into nightmare because each change would have to be done in each copy of module. So it's better to keep the code of module in one place and make it available for each project. There are multiple ways of doing that.
If you want to, you can turn your module into extension and make it publicly available through packagist as it was suggested by M. Eriksson in comments. After that you would simply add your extension through composer as any other dependency.
Composer also allows you to define and use private repositories if you don't want to publish your module at packagist. See composer documentation for more details.
The most trivial way is to simply put the code into separate folder outside of project. If you do that, you have to make sure that autoloaders in your projects are capable of finding the files locations to load classes. There are two options how to do that. In any case you will want to avoid conflicts with namespaces used by your project, that's why you need to use different namespace.
Let's assume that you've put your module files into folder /path/to/modules/myModule and all classes in your module belongs to namespace modules\myModule. You have to make sure that your webserver can access that folder and that it can run php scripts there.
First option is to use Yii's autoloader. That autoloader uses aliases to look for classes. If you add #modules alias and point it to /path/to/modules folder, the Yii autoloader will try to look for any class from modules\* namespace in /path/to/modules folder. You can add the alias in your config file (web.php, console.php or any other config file you use):
return [
// ...
'aliases' => [
'#modules' => '/path/to/modules',
// ... other aliases ...
],
];
The second option is to use project's composer.json file to set autoloader generated by composer to load your classes.
{
"autoload": {
"psr-4": {
"modules\\": "/path/to/modules"
}
}
}
You can find more info about this in composer's documentation.
Don't forget to run composer dump-autoload after you change autoload settings in your composer.json file to update the generated autoloader.

Finding the project root from within a composer package

I'm trying to provide potential locations of a config file within my package: .config.yml
At present, I've loaded an array within one of my classes with some typical locations:
protected $configDirectories = [
'./',
'./config',
'./app/config',
'./config',
'./vendor/name/packagename/config'
];
Problem is; my package is loaded into ./vendor/name/packagename and of course, ./ doesn't know how to get to the project root.
The aim is to allow users of this package to just drop .config.yml into any of the pre-specified directories and it should be picked up. How can I achieve this?
I had a similar situation. In my case, the front-end controller was in ./. So, I required the user of my package to do something like ...
\Wonderful\Package\Init::setRootDirectory(__DIR__);
(But I eventually decided that instead of having magic search order happening under the covers to locate the config file, I ended up having the one (or more) config files specified explicitly (can be anywhere with any name) ...
\Wonderful\Package\Init::loadConfigFile(__DIR__.'/config.yml');
\Wonderful\Package\Init::loadConfigFile(__DIR__.'/config.DEV-overrides.yml');
If you want to give the user the ability to configure your bundle, you MUST do it via semantic configuration and not via a specified and own config file. Do it the Symfony way.

registering Bundle to symfony kernel

Instead of Using composer I download zip file of a bundle and extract this bundle to my symfony project. I change all relative address for example I change all namespace Trsteel\CkeditorBundle; to namespace Acme\TrsteelCkeditorBundle; for doing this I searched the downloaded directory for every Trsteel\CkeditorBundle and change all of them to Acme\TrsteelCkeditorBundle now when I want to use this Bundle on my project I register this bundle to my appKernel.php of symfony project But I reached this error
Error: Class 'Acme\TrsteelCkeditorBundle\TrsteelCkeditorBundle' not found in /Users/kingkong/Documents/workspace/dev/Project/SRC/app/AppKernel.php line 45
File names should be the same as namespace structure, capitalization may be an issue, so check that.
You may want to place the bundle in this way - "Acme\Trsteel\CkeditorBundle\CkeditorBundle"
Check whether you have actually changed the folder structure from Trsteel\CkeditorBundle to Acme\TrsteelCkeditorBundle. And also check your routing files as well. (I assume you have done the routing part as the error won't say that it can't get to that location.)
Cheers!

moving bundle from vendor to src directory

I installed SonataMedia in the vendor/ directory of my project using composer and everything was working fine. I wanted to move the bundle to the src folder to keep everything tidy..
is there any way to move bundle from vender to src directory?
Yes, copy past the namespace directories to the src directory...
But really, why do you want this? The directory structure is not important and even if it was, it is better to put the 3th party bundles in the vendor directory to seperate your bundles from 3th party bundles
You must use Sonata easy extend and extend your bundle. This avoid breaks on bundle update.
By default easy extend create the extension in an app folder but you can tell him to put the extension in your src folder with the --dest parameter.
app/console sonata:easy-extends:generate SonataUserBundle --dest="./src"

Symfony 1.4 - Doctrine - Custom Plugin - How do I get plugin model files to reside in plugin directory?

I am creating a custom plugin, and am trying to keep all related model files contained within the plugin directory structure. However, when I build the model, some files get dropped into lib/model/doctrine/... and others in plugins/userPlugin/lib/model/... . According to Doctrine docs I can add a "package" option to the schema.yml file, and generated model files will be created in the location as defined by my dot-notation entry, for example:
# plugins/userPlugin/config/doctrine/schema.yml
connection: store-rw-user
options:
# Fully expect resulting model files to be dropped in this directory (vs the main model dir)
package: userPlugin.lib.model.doctrine
....
As mentioned, this config setup still results in model files being dropped into the main lib/model/doctrine directory. I even tried this, to no avail:
# plugins/userPlugin/config/doctrine/schema.yml
connection: store-rw-user
options:
package: userPlugin
package_custom_path: /tmp/userPlugin
....
Just wanted to see if the files were dropped in the /tmp directory, but they were not.
Before I start tearing apart the source code, I figured I would ask first, to see if there is something I am missing.
It's perfectly normal to get model files in your project directory after building. The purpose of this is to let you customize the plugin model on per-project basis, because the classes inside these files inherit from the classes defined in the plugin's files. I use plugins too, and most of the time, all the code I write resides in the plugin's model files.

Categories