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.
Related
I'm creating an app using grails that generates multiple files as a process output, and put them on some folders that later will be access by ftp by other people.
Everything works great except that in production the new created files are created with access only for the user that runs tomcat, meaning that when somebody connects to the folder using ftp the files can't be open because they don't have permission.
is there any way to set permissions from grails or configure tomcat in a way that every output can be access by other users?.
This might help. You can also look into executing shell commands but that may not be the best option.
I found out that there is actually a method for the class File that changes the permissions for an instance of file, I was trying to use it but I notice only changed the permissions for the owner, but with a slight change on the parameters you can tell it to apply to other users too.
File.setReadable(boolean readable)
File.setReadable(boolean readable,boolean ownerOnly)
So in my case file.setReadable true,false made the trick.
Check out the class methods for more info java.io.File
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 have used the cake schema create DbAcl before, succesfully at that. for some reason the output that i am now getting is not that which i require. the shell is returning some help options but will not create the aros and acos tables. help
I had to copy the path to the console folder to my environmental variables and restarted the command line. that did the trick
I am stuck in setting up environment for running cake bake.
In my development machine (using WAMP), I have several applications:
/{wwwroot}
/myapp-1
/myapp-2
/myapp-3
According to some tutorial online, in order to use 'cake' in command prompt, I have to add 'cake/console/' directory as 'PATH' environment variable.
Therefore, I add '{wwwroot}/myapp-1/cake/console' as one of the 'PATH' variables.
But the problem is, when I am going to 'cake bake' some models/controllers for 'myapp-2' or 'myapp-3', the system said something about database table not found and a like.
After some tracing, I suspect that the 'cake bake' is using the 'config' of 'myapp-1' because I am using the 'cake/console' there.
So, what is the proper structure of the environment 'cake bake' multiple applications?
Many thanks!
I would go to your appropriate app folder and directly reference the cake script. It should then use the correct config.
../cake/console/cake bake
there is also a parameter -app that you could use to specify which app you would like to use.
I am trying to use the Configure class in CakePHP, but I'm not sure if I am using it correctly. I have read through the cook book and the API, but I can't seem to do what I want.
I have created a configuration file: app/config/config.php. I can directly edit this file and set variables in there and access them using Configure::read().
Is it possible to update the values of the configuration file from the application itself, i.e., from a controller? I have tried using Configure::write(), but this does not seem to change the value.
app/config/config.php isn't a file that's automatically loaded by Cake. Either move these variables into app/config/bootstrap.php or tell your bootstrap.php file to load your custom file. You could also put your variables in app/config/core.php, but I'd recommend against that. I tend to like leaving that file alone and adding/overwriting values in bootstrap.php.
According to the API, Configure is supposed to be used "for managing runtime configuration information".
You can use its methods to create, read, update and delete (CRUD) configuration variables at runtime. The Configure class is available everywhere in your CakePHP application and therefore CRUD operations performed on its data in any place, including a controller.
If you are looking for persistent storage, you could consider a database (SQL or NoSQL). I would not recommend using a text file, as it raises a lot of security concerns. Even if security is not an issue, a database is propably a more fitting solution.
More on the Configure class in the Cookbook.