Arrange CakePHP plugins into subfolders - php

I've noticed some people mentioning a similar request for controllers and sometimes models, but I've been unable to find anything on arranging plugins in subfolders.
I want...
/app
/Plugin
/Modules
/Form
/Controller
/Gallery
/Controller
/SomeStandardPlugin
/Controller
..so that I can keep all the CMS functionality specific plugins separate.
I've tried:
CakePlugin::load('Form');
CakePlugin::load('Modules/Form');
CakePlugin::load('../Plugin/Modules/Form');
No matter which of the above I try, when I attempt to make use of the controller in one of the plugins, it says:
Error: FormsController could not be found.
Error: Create the class FormsController below in file: app\Controller\FormsController.php
(Which would be fine if I didn't want it in a plugin!)
The CookBook didn't mention anything about it either - is it just not supported or am I missing something?
FYI: I'm using CakePHP v2.2.3

The argument for CakePlugin::load is not a path
The first argument for this function, is the name of a plugin. This is the correct way to load a plugin:
CakePlugin::load('Name');
But it will only work if the plugin exists in a location configured using App::build
As such, to organize plugins into subfolders, it's necessary to declare all paths that contain a plugin:
// append app/Plugin/Modules to the path to look for plugins
App::build(array(
'Plugin' => array(
APP . 'Plugin/Modules'
)
));

Related

Can't import Vendor class into Component in CakePHP 2.5.1

I've been looking at all the related questions of this topic and none of the solutions provided (usually App::import() ) have worked for me, maybe because I have a different configuration, which is the following:
I have a regular cake installation which loads components from an external folder (so outside this installation). That works perfectly, even for the component I'm trying to use now (it works fine until I try to load the Vendor class). This Vendor class I want to have it outside the Cake installation as well (same as with the components). This is how this installation looks:
[root]
.......[shared_resources]
......................................[CakePHP]
........................................................[Components]
..............................................................................MyCustomComponent.php
........................................................[Vendor]
....................................................................[MyVendor]
......................................................................................MyVendor.php
......[MySite]
................... [cakephp typical folder structure]
In my site's bootstrap.php file I have App::build(array('Controller/Component' => array(dirname(ROOT) . '/shared_resources/CakePHP/Component/'))); in order to be able to load that component in any controller, which works fine, any component I put in that folder loads and works without issues.
Now, I'm trying to load the MyVendor class in the MyCustom component, but I can't get it to work, no matter what I try I keep getting class not found errors when trying to instantiate it.
I've tried using php's and Cake's require(), import(), App::import() and App::uses() with all possible combinations of paths (absolute and relative) without any success, puttin them before the declaration of the component class and inside the method that actually uses the vendor class. The last one I've tried is App::import('Vendor', '/absolute/path/to/shared_resources/Vendor/MyVendor/MyVendor.php'); for example.
I've also tried using App::build(array( 'Vendor' => array(dirname(ROOT) . '/shared_resources/CakePHP/Vendor/'))); in the bootstrap file, like with the components.
I don't know what else to try, any help would be much appreciated!!!
Oh, I've check with PHP that the file Vendor class file exists in that path too.
According to your folder structure,
To access your MyVendor.php, you should write like this
App::import('Vendor', 'MyVendor', array('file' => 'MyVendor/MyVendor.php'));
For more information, read http://book.cakephp.org/2.0/en/core-utility-libraries/app.html

laravel 4 create module and put controller , module and view inside module

I have worked on yii framework before and I had possibility to create module folder and inside this put eg: news module which was included controllers, views and module
I'm new in laravel and trying to create same thing MODULE
i tried the following inside routing
Route::get('/news','/modules/news/controllers/NewsController#index');
file exist but i'm getting
ReflectionException
Class /modules/news/controllers/NewsController does not exist
why ? what i'm doing wrong ?
The Route::get() function is looking for a (auto)loaded Class, not for a file on the disk to load, which is why you're getting these errors.
It's more Laravely (Laravelish?) to include:
Controllers in the /app/controllers/ directory
Views in /app/views/ directory
Models in the /app/models/ directory
And if you are starting out with Laravel, this might be the best way to get started. The autoloader knows where to look for your classes then, and everything gets handled automatically for you.
With the NewsController situated in /app/controllers/ you can do this:
// no need to start the route location with a slash:
Route::get('news', array('uses' => 'NewsController#index'));
You can "package" up functionality using Laravel's Packages, but it would be better to check out the excellent docs and then come back with specific questions..
Put your Laravel controllers in app/controllers, since that directory gets autoloaded, and it is where Laravel expects controllers to be.
Then you can use routes like this (example straight from the docs at http://laravel.com/docs/controllers#basic-controllers)
Route::get('user/{id}', 'UserController#showProfile');

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.

CodeIgniter - extend native library in multiple-site setup

I want to use a central CI setup for multiple sites. The way I handle this is I created a package called MPACK and added it to autoload in the config file of each site.
Folder Structure:
/main
/system (CI 2 System folder)
/MPACK
/site1
/application
site2
/application
Inside this MPACK I have share libraries, models, helpers, etc.
However, I would like to have an extended MY_Form_Validation that would be common to ALL sites. Adding the class file to /MPACK/libraries fails. Adding it to /site1/application works fine, as expected.
Is there any way to do this extending inside MPACK?
Thank you for your time.
Please try this:
// Placed your MY_Form_validation.php under MPACK/libraries
$this->load->add_package_path('/path/to/MPACK');
$this->load->library('form_validation');
You can get more information from CodeIgniter User Guide - Loader Class. :)
You can also autoload your package in /application/config/autoload.php : $autoload['packages'] = array('/path/to/MPACK');
EDIT: turn out that the above solution doesn't work, because Loader always look for APPPATH & BASEPATH first, and I not sure modifying this core class won't break something. Here is another solution in theory:
You should have your MPACK form validation lib, and sites' form validation lib should be symlinks to the MPACK one:
/site1/application/MY_Form_validation.php -> /MPACK/libraries/MY_Form_validation.php
If you just use everything from MPACK, nothing specifically for /site1 or /site2, just make a folder link:
/site1/application/libraries/ -> /MPACK/application/libraries/
Hope this help =)
You can read more here: http://codeigniter.com/wiki/Multiple_Applications_via_Symlinks/

Load single CakePHP plugin with App::build()

Is it possible to load a single plugin from outside the cake root using App::build()?
If I do:
App::build(array(
'Plugin' => array('/full/path/to/plugin_dir/')
));
..I can load a whole directory of plugins but what if I only want to use one of them? Is this possible? (I get errors when using a path to the specific plugin directory).
(P.s. This is cake version 2.1)
From the bootstrap.php in a baked application:
CakePlugin::load('DebugKit'); //Loads a single plugin named DebugKit
You have to add the directory with the plugin in it via App::build() and then the plugin itself with the method above.
While using "App::build()" you are not "loading" all the files in there. You are defining the paths where cake searches for php to include in case it has to.
Nothing will be loaded if it is not need since Cakephp 2.0. Everythings is about lazy loading ^^
How this is, what you are searching for ;)

Categories