Mark Adams
Mark Adams

Reputation: 184

CakePHP cannot find database configuration from shell in plugin

Background: Basically, my application has a plugin which has a Shell within it. This Shell is located in the plugin's Console > Command folder. Functions from this shell are intended to be ran from the command line.

My database configuration file (database.php) is located in the application's root Config folder. I access the database in several other instances so I know there's nothing wrong with the database configuration.

When I try to use any Model data retrieval methods (such as find(...)), I get the error:

The datasource configuration "default" was not found in database.php

This is occurring because it's looking for the database.php file inside the Plugin's Config folder, rather than the root Config folder. This only occurs when using a Shell, rather than in a Controller.

My Question: How can I tell my Plugin to use the root's database.php file instead of trying to find it in it's own Config folder, when using a Shell?

To reiterate: The Plugin uses the root Config/database.php file when retrieving data from a model in a Controller, but tries to use its own Config/database.php file when retrieving data from a model in a Shell.

Two things that I've tried that will work: 1) Moving database.php into the Plugin's Config folder and 2) Creating a symbolic link.

Both solutions seem unacceptable as I don't want to have two copies of my database.php file around, and creating a symbolic link isn't a great solution since this application will likely have to be distributing among different systems.

Thanks. I should mention that this is Cakephp 2.3.6

Answer (thanks user221931): Your working path needs to be the application path, not the plugin path. You can run the plugin shell using the plugin dot notation. Like this:

cake -app /path/to/app Plugin.shellName shellFunction

as opposed to how I was incorrectly doing it before:

cake -app /path/to/app/Plugin/pluginName shellName shellFunction

Upvotes: 1

Views: 1563

Answers (1)

user221931
user221931

Reputation: 1852

How about running the plugin shell using -app?

Changing Paths: Your working path should be the same as your application path. To change your path use the '-app' param. Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp

Upvotes: 1

Related Questions