1
votes

I am working on a legacy CakePHP 1.3 app and while I have years of experience with PHP, I am still finding my feet with CakePHP. I am following Chapter 4 'How to use the bakery' in Jamie Munro's Rapid Application Development with CakePHP, however the steps he suggests do not seem to go the way I'd expect them too.

I feel a good way of explaining this is going through the steps involved:

  1. Following the books 'Hello World' example outlined in earlier chapters, I have setup a basic CakePHP app at this location on my machine: /home/public_html/helloworld.local. I can see the 'Hello World' example in a web browser on my local machine when I access: http://helloworld.local/users/add

  2. Chapter 4 suggests that I move to this directory: home/public_html/helloworld.local/cake/console

  3. I then run: ./cake bake

  4. I get prompted to enter the location of the app and I add: /home/public_html/helloworld.local/app

  5. I then proceed to select defaults for the next few selections and there are no problems until I run into the line: Your database configuration was not found. Take a moment to create one.

I do not understand this since there is a database file configured in ~/public_html/helloworld.local/app/config/database.php, and when I access the helloworld app outlined earlier (available on my local machine at http://helloworld.local/users/add), there is a database connection successfully established and records can be inserted.

I have also tried re-entering my database details when offered the chance to by cake bake, but end up with the error after succesfully adding the correct details:

Fatal error: Class 'DATABASE_CONFIG' not found in /home/public_html/helloworld.local/cake/console/libs/tasks/db_config.php on line 260

But either way, it should have found the existing database connection details, so not sure what is going on.

3
You mention that the database config is in this path /public_html/setify.in/app/config/database.php which differs from the 'helloworld.local' path ?thaJeztah
Sorry, wrong paste. Have updated.fakeguybrushthreepwood

3 Answers

1
votes

For using console command like cake bake you have to use your operating system terminal(for linux)/ command prompt(for windows). So you have to do the step mentioned in step 2 and 3 in you console. You can read documentation here to know how to use console commands.

Then, make sure that you have the file home/public_html/helloworld.local/app/config/database.php. I hope you removed .default from its name and rename it to database.php. To link up your database with your cakephp project you have to specify credentials in database.php.

    var $default = array('driver'      => 'mysql',
                     'persistent'  => false,
                     'host'        => 'localhost',
                     'login'       => 'root',
                     'password'    => 'password',
                     'database'    => 'database_name',
                     'prefix'      => ''
);
1
votes

I don't have a running CakePHP 1.3 installation here at hand, but this is what is happening at that location:

// @link: https://github.com/cakephp/cakephp/blob/1.3/cake/console/libs/tasks/db_config.php#L260
config('database');
$db = new $this->databaseClassName; // i.o.w. $db = new DATABASE_CONFIG;

This line: config('database');

Does nothing more than including the database.php configuration file, simplified to;

include_once(CONFIGS . $arg . '.php'); // i.o.w. include_once(CONFIGS . 'database.php');

(https://github.com/cakephp/cakephp/blob/1.3/cake/basics.php#L77)

So IMO two problems may cause your error;

  1. app/config/database.php was not found

You can try to check if this outputs the right path:

die(CONFIGS . 'database.php');
  1. There is an error in your app/config/database.php, causing the DATABASE_CONFIG class to be malformed and unable to be initialized

A word of notice Aparently your running 'bake' for everything including setting up a new database configuration. This may overwrite your existing database configuration. It is possible to bake only parts of your application (e.g. bake controllers only or models). The manual on baking in CakePHP 1.3 is located here: http://book.cakephp.org/1.3/en/The-Manual/Core-Console-Applications/Code-Generation-with-Bake.html

And this If this is your first CakePHP project, you should realy consider the option to upgrade to CakePHP 2.x CakePHP 1.3 is really outdated and, although it's still able to run fine, I wouldn't invest too much time in 1.3 as a lot of things have changed in CakePHP 2.x. It's probably better to start with CakePHP 2.x then to start with 1.3 and learn things that no longer work in CakePHP 2.

0
votes

Copy your app/Config folder to app/Console, so the final path would be app/Console/Config. That worked for me.