Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP cannot find database configuration from shell in plugin
    primarykey
    data
    text
    <p><strong>Background:</strong> 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.</p> <p>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.</p> <p>When I try to use any Model data retrieval methods (such as find(...)), I get the error:</p> <blockquote> <p>The datasource configuration "default" was not found in database.php</p> </blockquote> <p>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.</p> <p><strong>My Question</strong>: 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?</p> <p>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.</p> <p><strong>Two things that I've tried that will work:</strong> 1) Moving database.php into the Plugin's Config folder and 2) Creating a symbolic link.</p> <p>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.</p> <p>Thanks. I should mention that this is Cakephp 2.3.6</p> <p><strong>Answer (thanks user221931):</strong> 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:</p> <pre><code>cake -app /path/to/app Plugin.shellName shellFunction </code></pre> <p>as opposed to how I was incorrectly doing it before:</p> <pre><code>cake -app /path/to/app/Plugin/pluginName shellName shellFunction </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload