I'm having some weird behaviour from the cake console and I can't figure out what could possibly be wrong!
I've used the cake bake console before and not had any problems so hopefully it's not something glaringly stupid.
I have the tables: users, images and folders.
Folders and images both have user_id's
When I run the cake bake all on the folders table it bakes the controller and model but there's errors baking the views. I figured perhaps you can't call a table folders because of conventions or whatever so I renamed it 'archives'.
Now when I run the console and cd to myApp/app and cake bake all I get the model:
1 archife
2..
archife??
My table is most definitely called archives. I've changed the name a bunch of times to other names to check and it only seems to be on the particular word archives which it turns into archife. I've checked other words with 'v' in it but they're fine.
So.. my questions are twofold. Can we not use the table name folders because there's some problem with it? It's the only name I've come across apart from pages which you can't use as a table name because it clashes.
And, why does cake bake the table archives to the model archife?
Model names should be unique...
As a general rule, don't use names for your tables that would result in a model class name that equals an existing class name, Folder for example is a utility class shipping with CakePHP, and this will cause problems with autoloading as you've experienced.
This is a problem that should/will be fixed with CakePHP 3, where namespaces are being used.
...and singular
archives being turned into archife sounds like it could be an Inflector bug/conflict, try
debug(Inflector::singularize('archives'));
It's working fine for me using CakePHP 2.5.1, ie it returns archive as expected, so I'd suggest to upgrade your CakePHP version, and report it as a bug in case it's happening with a recent version.
Related
I am using CakePHP 2.3.6. In a project, I implemented Acl. I followed the official tutorial given, populated the acos table by cake's shell scripting,used AclExtras plugin, then populated the aros_acos table using "customized" initDb function.
Everything is ok now, the tables are populated successfully. So, I thought I don't need the allow()/deny() functions, which I used before for Authorization. So I deleted these functions from the beforeFilter() functions from the corresponding controllers. But, when I deleted them, I cant access any page(fucnction) in my whole project.
To populate the acos table I used this command :
./Console/cake AclExtras.AclExtras aco_sync
To populate the aros_acos table I customized the initDB() and put it in the Users controller and run it.
All tables are populated, everything is good, but its not working the allow()/deny() functions defined before I implemented ACL.
My question is, if I use Acl, if I have all AROs & ACOs stored in the database, and if I define all permissions in the database, then why do I need those allow()/deny() functions ? And if I need those, then why should I use Acl ? My project was fine without the Acl implementation, with the allow()/deny() functions.
So, what should I do ?
Can anyone help me please ?
Thanks.
Ok,
Finally I got the ACL working. I found that its so easy, I just had to know the shellscrpting. I always knew that its implemented well in CakePHP, I just have to make it working in my project.
First of all, we have to make PHP and CakePHP executable from our shell/command prompt. I did it in Windows(7), will try for Linux & MAC later.
First, if you dont have PHP executable from your command prompt, go to My Computer->Properties->Environment Variables(forgot exact path, but you will get it easily). Then paste this c:\wamp\bin\php\php5.3.13; in the Environment Variable, where php5.3.13 is version-specific.
After that, paste this in the same place : cakephp\lib\Cake\Console. You can copy the cakephp folder to your htdocs/www permanently, for later use.
Now, run this in your command prompt : cake bake all, and follow the instructions. You must have to have a database, configured in your config.php file.
By now, you should be ready with the newly created project. Now follow the CakePHP documentation for ACL.
Remember, which functions/methods you want to be open for all kind of users, allow them explicitly by allow(), in AppController, or in the specific controller.
Suppose, you want pages/index,users/login,users/signUp - these 3 pages/functions to be open for all. So, allow() them in the AppController or in Pages & Users controllers.
I'm creating a CakePHP 2.3 advanced installation (several apps -websites- that share one same lib folder where all of cake's core files are located). This works without any problems, I just edit the core.php file in the Config folder for each app so it knows where to find cake's files. The file system looks something like:
[root]
[cake-core-files]
[websites]
[website-1]
[app]
[plugins]
[vendors]
[website-2]
...
[website-N]
These different apps are in fact different in some things (they are different websites) but at the same time there's many things that are common to all of them (for example some models, controllers, functions...). What I would like to do, if possible, is to have those apps also share a bunch of controllers, models, etc so I can put them in one place, instead of replicating them now for each app.
I've seen the concept of vendors and plugins in CakePHP (I actually use plugins in those websites, but from the /app/plugins folder), but I'm not sure if that would work in my case, or how I would set that up. I guess the idea would be to have another folder (for example [shared_objects]) at the same level of [cake-core-files] and [websites], but I don't know how I would have to configure cake to do that or how to call those objects from each app.
Any ideas?
EDIT
Based on the comments/responses below I'm trying to do this using the App:build() function in the bootstrap.php, but I can't get it to work. This is what I've done:
Added a new folder where I want to put the stuff to share between all apps:
[root]
[cake-core-files]
[shared-stuff] --> NEW FOLDER
[Model]
[Config]
[websites]
[website-1]
etc...
Placed the model User.php inside the new folder [shared-stuff/Model]
Added this line in the bootstrap:
App::build(array('Model' => array('/path/to/shared-stuff/Model')));
Deleted the model User.php from its original location [website-1/app/Model]
After this steps, it seems to work, the model User.php is loaded correctly from the [shared-stuff] folder (I've tested that printing App::objects('Model');, the User model is listed). However, it actually doesn't work, when I call that model from the UsersController in the login() function, the login doesn't work (although I don't receive any kind of error, even with debug set to 2).
This model uses a database configuration different from the default one (the users table is located in a different database than the default one). I don't know if this matters.
One thing is for sure, if I leave the same exact User.php model in its original location ( [website-1/app/Model]) it all works fine, including the login, so it's a problem with how I try to configure all this sharing stuff, not the model itself.
Any ideas what am I doing wrong?
I think it could be useful to share some controller/model between multiple websites, and do it without a plugin: Using shared controller/model lets you to overwrite it if needed. It should happen simply copying the controller/model in the website's correct folder and the system should use it instead of the shared one!
EDIT: Wonderful, it works, but i think there is a little error in cake's official documentation: All paths should be terminated with a Directory separator! In the cakephp book there aren't trailing slash. Add it to your App::build path and everything will work perfectly!
You can have plugins in the core Plugins/ dir
[root]
[lib]
[Cake]
[Plugins]
[Available]
[To]
[All]
[website-1] // the 'app' dir -> https://github.com/cakephp/cakephp/tree/master/app
[plugins]
[vendors]
[website-2] // you can have many of them named anything, 'app' is just one.
...
[website-N]
This folder specifically will make the plugins available to any app using the cake lib
EG:
Look at this. Copy app to website-1, repeat till website-n.
I'm having some trouble with a django database (postgresql backend).There was a model (a profile for users) in the project with some boilerplate stuff in it. This has sat in our project for a while, not being used. I actually got round to needing this, so I adjusted the models and created some initial migrations with South. On my dev box I dropped the entire db and syncdb'ed and migrated. This worked fine.
When I've pushed this out to production, I manually removed the old tables in postgresql and syncdb'ed and migrated. However, in my admin interface a DatabaseError is raised as some function is looking for a field on the old model. I've even dropped the entire postgresql database and syncdb'ed / migrated again and this still happens. The offendinging field is called gender (not one that I created). The migration works, and the database structure reflects my models, but for some reason the admin interface wants to find this (non-existant) gender field. This is the error:
DatabaseError: column user_profiles.gender does not exist LINE 1: ... "user_profiles"."id", "user_profiles"."user_id", "user_prof...
I understand this seems to be quite site specific, but perhaps I could get some pointers on how to debug this?
Thanks
If I understand your problem, your current code should not contain a reference to "gender" any more, since the old code was removed. Try to find a source file which still contains it:
find your-dir -name '*.py'|xargs grep gender
Or there is a pyc file, but the py file was removed. But Python still loads the pyc file....
If this does not help, please post the ascii traceback.
Im baking tables in cakephp. One table named abc which I baked successfully and I need to remove this table from database and also from the cakephp folder. I deleted all models, controllers, views and test fixture for that table. But due to some reasons now when Im baking my next tables it gives me an error "Missing database table 'abc' for model 'abc'. I dont know from where the error is coming. I deleted all files related to abc.
Try deleting all of the models in \app\models and then rebake them.
Try deleting content of the app/tmp/cache/models directory.
I am currently trying to build a cakephp app that will list items from a database, and there is a field in the database named picture. This picture field contains a string which is the primary picture, so for example ABCD, and then in the images folder this is ABCD.jpg
However there is usually various extra pictures for this particular item, which may be named ABCD1 or ABCD_2 or some other such variating suffix. I had previously written some script in php which used a glob function and counted the files and outputted them.
I am seriously struggling to do this in cakephp, at the moment there is several thousand images stored in the webroot of the server in /images and I understand that cake will be looking in the webroot of the app like /app/webroot, so is it possible to view their original location? or must they be moved...
I have read a little about the file and folder classes but I am struggling to comprehend them, not sure if my brains failed me here or if this is actually a difficult concept..
my question is how would I find any files that begin with this prefix in the picture field after selecting by the id of the item, to then display all those that match for that particular item?
thanks for your help!
Not a real answer to your question but you should start making a database relationship with your pics.
Check out hasMany to make a relationship between your Article (or whatever it is) and the Picture models. Now you will not have to look for each filename, as you'll have it in your database.