CakePHP 2.x: Alaxos ACL Plugin- configure the admin route - cakephp

i am a cakephp beginner , have not much exposure to cakephp.
I have followed installation step for Alaxos ACL plugin foe cakephp 2.0 from -alaxos site .. there second step is configuring admin routing .
that i have done by adding
Router::connect('/admin/acl', array('plugin' => 'acl', 'controller' => 'acl', 'action' => 'admin_index', 'admin' => true));
to my Cake/Routing/Router.php file and configuring app/Config/core.php: by adding following line
Configure::write('Routing.prefixes', array('admin'));
i am not sure whether this is the correct way of doing it...
On accessing the plugin http://localhost/cakeacl/admin/acl it gives error
**Private Method in AclController
Error: AclController::admin_index() cannot be accessed directly.**
Please help me ..Thanks in advance...

try to put only the following in the app/Config/core.php and remove the Router configurations.
Configure::write('Routing.prefixes', array('admin'));

Have you tried this guide http://book.cakephp.org/1.3/view/1543/Simple-Acl-controlled-Application from the official site yet?

Related

How to bake admin (prefixed) code with CakePHP 3?

Can anyone tell me what is the official way to create CRUD for admin back-end?
In CakePHP 2 the baked code was extended with 'admin_' before the function names and for the view files.
In CakePHP it seems I can't find any direct information on how it's done anymore. The bake console doesn't ask for admin anymore.
In this topic: https://github.com/cakephp/bake/issues/28 I see that they mention to use the --prefix extension but then the controller is placed in a separate /Admin folder while the CRUD functions keep having their normal name. And in some parts of the cookbook () I still see they mention functions like admin_view.
So can anyone tell me what is the official 'Cake'-way to do this from 3.2 on?
If you want to create Controller using cake bake. You can do this with below command:
bin/cake bake controller --prefix admin users
For view:
bin/cake bake template --prefix admin users
It creates the admin folder in the template directory, Then it creates the folder for users, then it includes the files. for admin prefix folder structure like template/admin/users/index.ctp
See official cookbook documentation
Also In your config/routes.php add this:
Router::prefix('admin', function ($routes) {
$routes->connect('/', ['controller' => 'Users', 'action' => 'index']);
$routes->extensions(['json', 'xml']);
// All routes here will be prefixed with `/admin`
// And have the prefix => admin route element added.
$routes->fallbacks('DashedRoute');
});
That's how things work now in CakePHP 3, prefixed methods are gone, prefixes now do generate separate controllers in sub-namespaces, for smaller/simpler controllers, and for proper separation, not only on controller level, but also on template level, where the templates are expected to be placed in separate folders accordingly.
The admin_view example you are referring to is just an example that should show how to manually set a custom layout for specific actions, it has nothing to do with prefix routing.
So, if you want to use prefix routing, then the "official" way is to use the --prefix option.
See also
Cookbook > Routing > Prefix Routing
Cookbook > Bake Console > Code Generation with Bake
Below is the bake command to bake all prefix controller and templates for users table
cake bake all users --prefix admin
And here is the route code to make it working:-
Router::prefix('admin', function ($routes) {
// Because you are in the admin scope,
// you do not need to include the /admin prefix
// or the admin route element.
$routes->connect('/', ['controller' => 'Users', 'action' => 'index']);
$routes->extensions(['json', 'xml']);
// All routes here will be prefixed with `/admin`
//$routes->connect('/admin', ['controller' => 'Order', 'action' => 'index']); // call other controller like this
// And have the prefix => admin route element added.
$routes->fallbacks('DashedRoute');
});
This will work for me hope it will work for you :)

cakePHP without domain name

I've set up my Raspberry Pi 2 with a nginx, php, mysql environment and installed cakePHP with composer.
Now the cakePHP landing page looks weird. I'm assuming that this issue is related to my nginx vhost configuration. (Conf with vhost works, CSS files loading)
The question is: is it possible to use cake without vhost conf?
The route is set to the respective folder:
$routes->connect('/test/', ['controller' => 'Pages', 'action' => 'display', 'home']);
With best regards,
Phil
Solved the problem by adding these lines into my /etc/nginx/sites-enabled/default conf-file:
location /test/ {
alias /usr/share/nginx/www/test/webroot/;
}

Migrating from cakephp 1.3 to cakephp 2.4

I am migrating application code from cake 1.3 to cake 2.4. I am following cakephp migration guide.
After following the steps mentioned there I am sill unable to run my code and getting this error:
Controller class Controller could not be found.
I checked the error log in cakephp and found:
2014-06-10 18:37:56 Error: [MissingControllerException] Controller class Controller could not be found.
Exception Attributes: array (
'class' => 'Controller',
'plugin' => NULL,
)
I am trying to debug it but no results.
I have had the same issue today.
You need to have the following 2 lines in your app/Config/routes.php
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
Also, make sure you have updated the .htaccess files in /, app/, and app/webroot.

How do I setup admin routes in CakePHP?

this code (http://bin.cakephp.org/view/172084837) is added to routes.php to connect from "/admin/pages/add" to "/admin/posts/add", but this error is occured: PagesController could not be found.
Enable Admin Area from app/Config/core.php
Routing.prefixes = array('admin', 'manager');
I hope this will work for you.

Caching plugin and normal controllers with duplicate names

I'm running into a problem related to caching, plugins and duplicate model names in Cake 2.0. My application has several controllers containing only actions for public use (view, index and equivalents). The data is managed by a CMS which is added as a plugin, some names of the plugin's controller are the same.
For example, I have a PostsController in my application and a PostsController for the plugin. The plugin controller extends PluginAppController and the public controller extends AppController as per the manual. As soon as caching is kicked in (by setting debug to 0) the problems start. Cake tries to access a non-existing add action in the controller which extends AppController and the public application tries to access methods from the PluginAppController.
I don't understand why Cake would do this and it creates all kinds of errors (blank pages, lost sessions) which aren't logged properly as well. Everything was working well while the app still ran on Cake 1.3 and also in 2.0 production mode.
The file cake_core_file_map in the /tmp/cache/persistent/ directory seems to be causing the issue. As soon as I remove this and reload either of the views, it renders correctly. So the procedure is as follows:
Load http://www.example.com/admin/posts successfully;
Load http://www.example.com/posts (it fails to render);
Clear the cache (or just cake_core_file_map);
Load http://www.example.com/posts successfully;
Load http://www.example.com/admin/posts (which now fails to load properly).
My guess is Cake fails to save the correct references to the plugin and main application paths in cake_core_file_map, but I have no clue how to force Cake to behave nicely in that regard.
Does anybody know how to stop Cake from confusing the plugin's controllers with the other ones with duplicate names?
EDIT
This issue might be related to a bug in Cake, as this report mentions similar problems and cake_core_file_map as well. The fix mentioned here doesn't work unfortunately.
EDIT 2
There is indeed some custom routing going on, which was working normally in Cake 1.3. This is from routes.php:
Router::connect('/plugin_name', array('plugin' => 'plugin_name', 'controller' => 'users', 'action' => 'login'));
Router::connect('/admin/*', array('plugin' => 'plugin_name', 'controller' => 'posts', 'action' => 'index'));
May be it would be helpfull to override Cake' standard cache file names for Plugin to make Cache engine keep it separately.
In main bootstrap file while loading plugin:
CakePlugin::loadAll(array('Plugin' => array('bootstrap' => true));
In Plugin direcrory
/app/Plugin/Plugin/Config/bootstrap.php
<?php
Cache::config('_cake_core_', array(
'engine' => 'File',
'prefix' => 'cake_core_plugin_',
'path' => CACHE . 'persistent' . DS,
'serialize' => true,
'duration' => '+999 days',
));
?>
Are there conflicting routes between the main app and the plugin? This sounds like you may need to create a route for your /posts and another for /admin/posts in your main app. This should override the routes from the plugin causing any conflict. Of course, clear your cache before trying the change.
//main app posts route
Router::connect(
'/posts',
array(
'controller' => 'Posts'
'action' => 'index'
)
);
//plugin posts route
Router::connect(
'/admin/posts',
array(
'controller' => 'Posts'
'action' => 'index',
'plugin' => 'CmsPlugin'
)
);
This turns out to be a known issue (which doesn't make it less annoying) and will only be fixed in a next major release, as per this Cake bug report.
PHP 5.2 doesn't have namespace support which is apparently needed for Cake to support duplicate classnames. PHP 5.3 has namespace support and Cake 3.0 will require that version.

Resources