Cakephp share database configuration for multiple apps - cakephp

I have a CakePHP installation with multiple apps that has this structure:
/cake-1.3.10
/cake-2.3.0
/apps/app 1
/apps/app 2
/...
/apps/app N
/apps/_shared/Cake_v1/Component
/apps/_shared/Cake_v1/Model
/apps/_shared/Cake_v2/Component
/apps/_shared/Cake_v2/Model
So what happens here is that all the apps grab the v1.3 or v2.3 cores (depending on which version of the framework they use). In addition, I have some Components and Models that all the apps share. Each app loads those from the _shared folder depending on its version.
Until here all works great.
Now, I would like to do the same for the database configuration. Each app has its own /config/database.php file. How would I go about making it so ALL apps share the same database.php file? Actually I would have 2 database.php files, one per version, since they're different (like with Components and Models). But I'm not sure what exactly I need to change to accomplish that.

I don't see that there is easy CakePHP way. You have to modify /lib/Cake/Model/ConnectionManager.php . In version 2.3 on line 69 there is
include_once APP . 'Config' . DS . 'database.php';
I don't see there any code that allows the configuration. It looks hardcoded.
More elegant way is that you make symbolic links as #Kai mentioned. Then you can upgrade CakePHP without having to remember about your little hack.

Related

How to get from zero to Mobile Web App with Data in 60 seconds

I know that all these components exist, however I really am trying to figure out if someone has brought all these together.
Here is what I need:
JavaScript/NodeJS core application boilerplate/framework
With a website, HTML app (aka PhoneGap or even better Ionic), and ideally option to add something like a desktop app (like electron) client flexibility
All with possibility of different/specialized frontend code so all assets and HTML could be packaged into the app
Ideally kept in one GIT repo
With shared code amongst all UIs
Ability to use Angular 2 in all environments (or something similar)
Realtime? standardized data connection with data source (like meteor's DDP), I really dislike polling and I don't want to have to write my own data protocol
Have some kind of authentication capacity
Already exist in some way
What I have been eyeballing thus far is Ionic2 on top of Meteor, however it is remarkably difficult to find an actually working example of them playing together and I have not found any with separate codebases between the two interfaces.
To clarify, below is sort-of what I envision for a folder structure:
public/
common/
models/
business-logic/
server/
web/
desktop/
mobile/
And in that, all UIs and server can import from the common folder.
The end goal is to have something like Slack where they have 3 different ways of accessing the same data using the same rules but can really specialize in each interface type.
Does this exist?
I am really looking to have something that can be started with:
git clone http://github.com/a/bc
npm install
# do some other things that are documented
meteor run ios
Or am I not gonna have my cake and be able to eat it too?
I know I am shooting for the moon, but I know I can't be the first person looking to do this
For the backend I think that LoopBack may be a good bet if you want fast developement.
They have some examples for iOS, Android and Angular apps on their website:
You may get some ideas from their documentation or several example projects on GitHub.
LoopBack is currently backed by IBM.

CakePHP create folder in controller? [Need Expert Advice]

How is it possible to have folder in controller?
For example this scenario: We have multiples clients and each clients might have different package that share the common controller or different controller based on their own request. So I was thinking to separate them by directory in the controller.
Any Expert in Architecture can help this?
This is probably possible, but is certainly not the way you should do things with Cake (or MVC in general, probably).
I suggest that you have a separate app for each client. If you have any specific questions regarding this, or would like to add more information to your question about what you're trying to do, I can try to give you a more in-depth answer.
Without knowing more it is hard to say.
I assume you have one app that is used by multiple clients through subdomains or something else to make a difference between who is using it.
You can have a plugin per client that extends the base apps controllers as needed. You also can have different models and views then. Use routes to make the different named controllers match always the same URLno matter what client is logged in.
I would prefer a one app solution over multiple applications because it reduces the maintenance overhead a lot. But if you want to for multiple apps I would build the core of the application that is shared by all sites as a plugin itself. Using git and submodules you can then even control what version of the core module each site is using.

Adding CakePHP core features in an older version of CakePHP

I am using CakePHP 2.2 and I will probably need to use SMTP with TTL which is only available at CakePHP 2.3.0.
The additions for this new feature are documented here:
https://github.com/cakephp/cakephp/pull/734
And i was wondering where should I add this code in my CakePHP project as I guess the core folders should stay untouched.
Could I do it using the app\lib folder? In that case, how should I add the content? Do I need to follow any structure? How Cake would detect it?
Thanks.
Just follow the CakePHP Migration guide and update to 2.3.
Honestly, I didn't even read through the migration guide, I just swapped into 2.3 and everything has just worked. It doesn't appear that there are many changes to existing code - just improvements / additions, so you'll likely not have to do any code modification.
I like to keep my versions of Cake separate (see advanced installation), but if you're on the normal install, just replace the files within /lib/Cake/ with the new versions files.

How to handle the deployment and updates of multiple installations of one CakePHP web-app?

I made a simple CMS with CakePHP to handle a small (but growing) number of websites. The CMS is constantly evolving as I regularly add features to a development version on my own machine.
I use SVN to trace the evolution of this development version, and that's pretty much it. To make a new website, I basically copy/paste the dev folder and modify the necessary files before uploading the new website by FTP.
One problem is in the end, every website installation is independent and if I want to add some new features to existing websites, I have to copy files by hand.
Another problem is that some websites have modified versions of the CMS because of specific needs: some controller classes have specific methods not present on the local version.
To sum it up:
I have one base CakePHP app regularly evolving
There are multiple versions (=websites) of this app already installed on different servers
Some websites have custom code included not present in the base version
I want to be able to easily update all the present and future websites when I improve the base app, without breaking some possible specific parts
Knowing it's a CakePHP app, what would you do? How should I change my code to manage at the same time the core and the specific code?
Thanks in advance!
... some controller classes have specific methods not present on the local version.
You might also consider the option of setting up additional class paths within each of your website applications. You can tell CakePHP to check other directories entirely for files missing from the current application. For example, you could have the following directory structure:
/app1 - a standard client's website application
/app2
/app3 - a custom client's website application (with custom controller)
/core - the core CMS application
/cake
By adding the following to your /appN/config/bootstrap.php files, you are telling CakePHP to look for controllers in /core/controllers if it can't find one it's looking for in the current application.
App::build(array(
'controllers' => array(ROOT . DS . 'core' . DS . 'controllers' . DS),
));
This would, for example, allow you to put all your CMS controllers in /core/controllers and delete all your /appN/controllers directories. Only where a client needed a controller customized (ie. /app3 above) would you create a controllers directory, copy the specific controller across and make modifications (adding methods and such).
(This is the approach the developer of Wildflower CMS took - note the /wildflower directory.)
Using version control software (like SVN) would probably do the trick for you. Each website you work on could be a branch that follows the main branch of development. Every time you make a change that you want to apply to every site, you'd update the main branch and then have every sub branch import the changes from the main branch.
Mind you, I'm more used to how Git works, so this scenario might work better in Git than in SVN, ymmv.

Is CakePHP "cake bake" command produces an instance dependent to the core CakePHP?

I am a total dummy to programming so pls understand if my question might sound dumb.
I successfully baked a cakephp website using "cake bake" command. I baked it in my webroot (C:\wamp\www) along with my core CakePHP. Then I decided to transfer my core CakePHP to another location so to prevent from making any accidental changes. When I tried to run the website after the core cakePHP was transfered I got 3 errors:
Warning: include(cake\bootstrap.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\cakeauth\webroot\index.php on line 76
Warning: include() [function.include]: Failed opening 'cake\bootstrap.php' for inclusion (include_path='C:\wamp\www\cakephp\cakephp_1.3.8;C:\wamp\www\cakeauth\;.;C:\php\pear') in C:\wamp\www\cakeauth\webroot\index.php on line 76
Fatal error: CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your \cake core directory and your \vendors root directory. in C:\wamp\www\cakeauth\webroot\index.php on line 77
My question is, how come the "baked php site" still need the core CakePHP? I think it should be stand alone. What if I am gonna transfer the site to another server / computer, do I have to transfer the core CakePHP along with it? I wanna if there's any work around for this. Pls help...
The bake console command only generates the stub classes for your MVC structure. It still depends on the cake folder for the library support.
You can still move your cake folder around, but you need to specify the new location when you do move it.
You can also run multiple cake applications that depend on the same library.
Have a look at the advanced installation options in the bakery : http://book.cakephp.org/view/915/Advanced-Installation
The Cake Bake command only creates the default models, controllers and views based on your database structure, it does not build an out-of-the-box application, like a compiler.
Your app still requires the CakePHP core files to be available to work, this is true with all frameworks, you cane however run multiple apps with their own app folder off one cake folder. You just need to update all the include paths in index.php to get yourself started.

Resources