Search code examples
phpcakephpscaffolding

Cakephp baking view problems on mac os


im new to cake and i have some problems while baking... I'm using cake php 2.2.1 on a MAMP server on MAc OS. I have turned off plurar/singlar infector... And i try to bake some tables:

CREATE TABLE users (
    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(255) NOT NULL UNIQUE,
    password CHAR(40) NOT NULL,
    email VARCHAR(40) NOT NULL,
    group_id INT(11) NOT NULL,
    created DATETIME,
    modified DATETIME
);# MySQL returned an empty result set (i.e. zero rows).

CREATE TABLE users_groups (
    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    created DATETIME,
    modified DATETIME
);# MySQL returned an empty result set (i.e. zero rows).

CREATE TABLE novosti (
    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    url VARCHAR(255) NOT NULL UNIQUE KEY,
    user_id INT(11) NOT NULL,
    title VARCHAR(255) NOT NULL,
    body TEXT,
    published INT(1) DEFAULT 1,
    created DATETIME,
    modified DATETIME
);# MySQL returned an empty result set (i.e. zero rows).

CREATE TABLE meta (
    id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    controller VARCHAR(255) NOT NULL UNIQUE KEY,
    action_name VARCHAR(255) NOT NULL,
    action_id VARCHAR(255),
    title VARCHAR(255) NOT NULL,
    keywords VARCHAR(255) NOT NULL,
    description VARCHAR(255) NOT NULL,
    created DATETIME,
    modified DATETIME
);# MySQL returned an empty result set (i.e. zero rows).

So when i "cake bake all" - "users_groups" i dont get errors, but if "cake bake all" other 3 tables i get the same error, so i get a model and a controller file but not the view file... So the problem is in baking view files.. Here is my console log:

What would you like to Bake? (D/M/V/C/P/F/T/Q) 
> v   
---------------------------------------------------------------
Bake View
Path: /Applications/MAMP/htdocs/app/View/
---------------------------------------------------------------
Use Database Config: (default/test) 
[default] > 
Possible Controllers based on your current database:
---------------------------------------------------------------
 1. Meta
 2. Novosti
 3. Users
 4. UsersGroups
Enter a number from the list above,
type in the name of another controller, or 'q' to exit  
[q] > 1
Would you like bake to build your views interactively?
Warning: Choosing no will overwrite Meta views if it exist. (y/n) 
[n] > y
Would you like to create some CRUD views
(index, add, view, edit) for this controller?
NOTE: Before doing so, you'll need to create your controller
and model classes (including associated models). (y/n) 
[y] > y
Would you like to create the views for admin routing? (y/n) 
[n] > n
Error: Table action for model Action was not found in datasource default.
#0 /Applications/MAMP/htdocs/lib/Cake/Model/Model.php(3180): Model->setSource('action')
#1 /Applications/MAMP/htdocs/lib/Cake/Model/Model.php(1301): Model->getDataSource()
#2 /Applications/MAMP/htdocs/lib/Cake/Model/Model.php(1389): Model->schema()
#3 /Applications/MAMP/htdocs/lib/Cake/Model/Model.php(1375): Model->hasField('title', false)
#4 /Applications/MAMP/htdocs/lib/Cake/Model/Model.php(863): Model->hasField(Array)
#5 /Applications/MAMP/htdocs/lib/Cake/Console/Command/Task/ViewTask.php(459): Model->__get('displayField')
#6 /Applications/MAMP/htdocs/lib/Cake/Console/Command/Task/ViewTask.php(284): ViewTask->_associations(Object(Meta))
#7 /Applications/MAMP/htdocs/lib/Cake/Console/Command/Task/ViewTask.php(223): ViewTask->_loadController()
#8 /Applications/MAMP/htdocs/lib/Cake/Console/Command/Task/ViewTask.php(90): ViewTask->_interactive()
#9 /Applications/MAMP/htdocs/lib/Cake/Console/Command/BakeShell.php(110): ViewTask->execute()
#10 /Applications/MAMP/htdocs/lib/Cake/Console/Command/BakeShell.php(131): BakeShell->main()
#11 /Applications/MAMP/htdocs/lib/Cake/Console/Command/BakeShell.php(131): BakeShell->main()
#12 /Applications/MAMP/htdocs/lib/Cake/Console/Shell.php(393): BakeShell->main()
#13 /Applications/MAMP/htdocs/lib/Cake/Console/ShellDispatcher.php(201): Shell->runCommand(NULL, Array)
#14 /Applications/MAMP/htdocs/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
#15 /Applications/MAMP/htdocs/app/Console/cake.php(33): ShellDispatcher::run(Array)
#16 {main}

Help plz guys %)


Solution

  • I just had a similar problem. In your "meta" table, you have a field called "action_id". Cake is trying to make the associations to a table/model named actions. It looks like you are missing that table. Create your actions table and try that. I see another problem that I ran into as well. Cake likes for you to minimally have id, name, created, and modified. Sometimes it works without name, but I have seen problems when I don't have it.

    Good luck!

    Jim