Using Composer in CakePHP
Composer, a magnificent dependency manager. CakePHP, a brilliant MVC framework. What's stopping you from using both in your application? Nothing at all! Personally, I have been using Composer exclusively in my applications to handle all my dependencies and even my CakePHP plugins. It's very easy to do.
The first thing you need to do is create a composer.json file within your application. It's best to place the file in app/composer.json as it would share the same directory structure with Vendor. Here's a quick example:
{
"config": {
"vendor-dir": "Vendor"
},
"require": {
"mjohnson/uploader": "4.*",
"mjohnson/decoda": "6.*"
}
}
Since this is an application and not a dependency, all you need to define is the "require" property. We also set the vendor folder to use CakePHP's naming convention, because why not?
To benefit from Composer's autoloader, include the autoload.php file at the very top of Config/core.php.
require_once dirname(__DIR__) . '/Vendor/autoload.php';
Brilliant! Now we have full dependency and autoloading support. Can't get easier than that.
23 Comments
I have exactly the same error, no matter what plugin I try to install with composer.
Any help ?
"
> Console\cake composer.c update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for mjohnson/forum 4.* -> satisfiable by mjohnson/forum[4.0.0].
- mjohnson/forum 4.0.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
"
However this extension is installed and enabled on my server, that's why I need some help.
Thanks!
What I do not understand is how you want to recursively load repositories as it is not possible http://goo.gl/EUPjW
Let me tell you example.
Creating cakephp application which will use your forum plugin. So getting clean copy of cakephp, then in ROOT, or APP I would create composer.json which would refere your forum plugin
running composer install I would expect the forum plugin is installed as welll as admin and utility plugin (http://goo.gl/w7znY). the forum is installed - good, but the required plugins admin and utility ARE NOT.
Any idea how to solve this problem since you decided to use comopser only?
Thanks in advance
You said that by manually installing the files can avoid composer But where can i get these files.
And where to install, will you please tell me clearly.
I dont want to use composer but i want to use latest 4.0 version.
Error: Class 'Transit\Transit' not found
File: C:\xampp\htdocs\upload\Plugin\Uploader\Model\Behavior\AttachmentBehavior.php
Line: 225
Please, help
I believe Miles have done an excellent job of creating these plugins and other script to help fellow coders.
But I also believe the documentation (especially installation instruction) does confuse a lot of beginners like.
I think we should help Miles to write a beginner level tutorials of how to use all the pieces together.
I am still struggling with lots of issue regarding the installation otherwise I would have written something on this.
What do you think?
Error: Class 'Transit' not found
File: E:\websites\cake230\bgsite\Plugin\Uploader\Model\Behavior\AttachmentBehavior.php
Line: 225
please which folder or file should I paste
{
"config": {
"vendor-dir": "Vendor"
},
"require": {
"mjohnson/uploader": "4.*"
}
}
please this is my skype id: simmysoft
https://github.com/uzyn/cakephp-composer
As in "README" states: "There is no need to pre-install Composer." and it's true - this plugin do all the hard work.
I've been trying to get image uploads working for 3 full days now with no success for one reason or another so I just need a quick solution that works. I'm a bit new and I reckon I've bitten off more than I can chew.
http://milesj.me/code/cakephp/uploader/logs
what's different between installing 3.6 and 4.0.4?
thanks for the efforts by the way, I hope I can get this working
https://github.com/composer/installers
Can you please explain how I suppose to add Plugins to my project?
For instance, I have a project that's using your Forum plugin.
If I'll add the Forum plugin to the project composer.json - the Forum will be located in the Vendor folder, while Cake will look for it in the Plugin folder.
Please advise,
thanks!
I do not understand how to install the plugin.
Can you explain more about this new procedure?
Thank you very much
and is there any working script which can guide which file contains what? like what and how to write in controller? your real documentations users two different words "plugin" and "vendor". I am confused between.
Help is appreciated as I am very hopeful about using this script in my project.
For this particular project I'm working on right now, I don't have access to the console, so I can't install the Composer. What can I do?