CakePHP Plugin - Error "Controller could not be found" - cakephp

I'm currently using CakePHP 2.5.2
I want to integrate a plugin to manage Users.
I tested it in a first time as a single CakePHP Application (controllers in app/controller, models in app/model, views in app/view/Users): was ok.
I'm trying now to convert it as a plugin:
I've created a folder UserManager in app/plugin.
When I try to go to the url of one of my controllers, I get the message Missing Controller.
All plugin are loaded in Bootstrap.php (CakePlugin::loadAll();).
I tried to find similar problems vs solutions but no one was relevant with my problem (I tried some proposed solutions but root causes were different.
When I look at DebugKit in Include section, I can observe that my DebugKit plugin is loaded but not my other plugin...
Could some one suggest me a solution ?
Thanks in advance.
(Please find bellow a description of the code)
I added controllers, models and views as follows (skeleton generated by Bake and checked: ok):
1) Models in app/plugin/model
UserManagerAppModel.php
<?php
App::uses('AppModel', 'Model');
class UserManagerAppModel extends AppModel {
}
?>
User.php
<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends UserManagerAppModel {
...
}
?>
2) Controllers in app/plugin/controller
UserManagerAppModel.php:
<?php
App::uses('AppController', 'Controller');
class UserManagerAppController extends AppController {
}
?>
UserController.php:
<?php
class UsersController extends UserManagerAppController {
public $uses = array('UserManager.User');
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('*');
}
public function login() {
}
...
?>
3)Views in app/plugin/view/Users
Nothing special.

I think it is an issue with your path names: They have to include the plugin name. Plus the folder names have to start with a capital letter by convention. For example, UserManagerAppModel has to be in the following file: app/Plugin/UserManager/Model/UserManagerAppModel.php.
See also http://book.cakephp.org/2.0/en/plugins.html#creating-your-own-plugins

Since I believe has included AuthComponent settings in your AppController loginAction note the call and check the name of your plugin. In my case the plugin name is Barracuda, the error does not occur stopped until the call was made ​​for barracuda, with the first letter in lower case.
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
'plugin' => 'Barracuda'
),
for
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
'plugin' => 'barracuda'
),

Related

CakePHP2 created plugin not found

When open page I get error:
Plugin Authority could not be found.
Error: An Internal Error Has Occurred.
I created new plugin under app/Plugin with this structure:
Green color represents newly created files.
I created this plugin the same way all other plugins are made (white directories).
My route to page is:
Router::connect('/authority', array('plugin'=>'Authority', 'controller' => 'Authority', 'action' => 'index'));
My routes.php include this line:
CakePlugin::routes();
This is example of some other route that is working:
Router::connect('/login', array('plugin' => 'users','controller' => 'users', 'action' => 'login'));
Here are some other files from the plugin:
AuthorityAppController.php
<?php
class AuthorityAppController extends AppController {
}
AuthorityController.php
<?php
class AuthorityController extends AuthorityAppController {
public function index(){
}
}
AuthorityAppModel.php
<?php
class AuthorityAppModel extends AppModel {
}
And this is my bootstrap line of code for activating plugins:
bootstrap.php
CakePlugin::loadAll(array( 'routes' => true ));
The issue was with the cache. I cleared tmp directory and it works now.
cd app/tmp
rm -rf *

Create plugin cakephp and use it in browser

I'm trying to create a plugin, this is my folder layout;
in bootstrap.php
CakePlugin::load('ContactManager');
in routes.php
Router::connect(
'/ct/',
array(
'plugin' => 'ContactManager',
'controller' => 'Contacts',
'action' =>'index'
)
);
ContactManagerAppController.php
<?php
class ContactManagerAppController extends AppController {}
ContactsController.php
<?php
class ContactsController extends ContactManagerAppController {
public $uses = array('ContactManager.Contact');
public function index() {
//...
}
}
ContactManagerAppModel.php
<?php
class ContactManagerAppModel extends AppModel {}
Contact.php
class Contact extends ContactManagerAppModel {}
How do I display index.ctp in my browser
index.ctp
<?php echo 'hello'; ?>
Requesting http://localhost/cakephp/ct/ContactManager/Contacts gives a missing controller error, instead of my plugin controller index:
You should be able to access your plugin's Contacts Controller (without setting up routes) from /contact_manager/contacts. So by the looks of your question the absolute URL should be:-
http://localhost/cakephp/contact_manager/contacts
If this is not working then there's something wrong with the plugin's setup. Make sure the plugin files are readable and that the filenames and classes are all correct. Your plugin structure looks good otherwise.
If the above URL works then (and only then) you can consider re-routing it. To do this you need to do something like this (preferably in /app/Config/routes.php):-
Router::connect(
'/ct/',
array(
'plugin' => 'contact_manager',
'controller' => 'contacts',
'action' =>'index'
)
);
If the route does not work try checking that nothing is overridding it elsewhere in your routes file.
You should use snake case (e.g. 'contact_manager') not camel case (e.g. 'ContactManager') in your route parameters.
This is my answer ---> thanks all
http://i.imgur.com/Ju8mq4D.jpg
in Controller:
AppController.php
ContactsController.php
in Model
AppModel.php
Contact.php
in View/Contacts
index.ctp
app/Config/routes.php
Router::connect('/ct', array('plugin'=>'ContactManager', 'controller' => 'contacts', 'action' => 'index'));
app/Config/bootstrap.php
CakePlugin::load(array('ContactManager' => array('bootstrap' => true, 'routes' => true) ));

CakePHP 2.x custom "Authentication adapter "LdapAuthorize" was not found

I'm building an application using CakePHP and trying to incorporate a custom authentication object but it does not seem to be able to find it. I get the following error when I try to log in: "Authentication adapter "LdapAuthorize" was not found". I have created the file app/Controller/Component/Auth/LdapAuthorize.php with my code for my authentication. Near the top of "AppController.php" I have
App::uses('LdapAuthroize', 'Controller/Component/Auth/LdapAuthorize');
and within the AppController class I have
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'pendings', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authorize' => array('Controller'),
'authenticate' => array('LdapAuthorize')
)
);
and then in my UsersController.php I have the following login function.
public function login() {
if($this->request->is('post')) {
if($this->Auth->login()) {
// My Login stuff...
}
else
$this->redirect(array('controller'=>'someController', 'action'=>'someAction'));
}
}
If anyone has any idea why it can't seem to load my custom authentication object that would be awesome. Thanks!
I put my custom authentication class inside Controller/Component/Auth. For example, the name of my class is CustomUserAuthenticate and the path to the file is,
Controller/Component/Auth/CustomUserAuthenticate.php.
Then in my AppController I added the following to the authenticate array,
class AppController extends Controller {
public $components = array(
'Auth' => array(
/** Any other configuration like redirects can go here */
'authenticate' => array(
'CustomUser'
)
)
);
}
The string in the authenticate array must match the name of the class except for the Authenticate word.
My CustomUserAuthenticate class extends CakePHP's Controller/Component/Auth/BaseAuthenticate and overrides the authenticate method. CakePHP's documentation states that this is not required. I haven't tried that way.
I think your App::uses() is wrong so it can't find the class. Your current code:
App::uses('LdapAuthroize', 'Controller/Component/Auth/LdapAuthorize');
Is trying to find Controller/Component/Auth/LdapAuthorize/LdapAuthroize.php
The first parameter is the class name (you have a typo with that), the second is just the path to the directory containing the class, you don't need to add the class name again.
Try this:
App::uses('LdapAuthorize', 'Controller/Component/Auth');

Cakephp Simple Authentication tutorial page not redirecting to current page

I am start going through the cakephp tutorials, I copy the source code exactly as shown in the tutorial.
I have done the Blog tutorial and all seems good, now I am onto the "Simple Authentication and Authorization Application" (http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html) tutorial, but are running into this issue.
The add page loads fine:
".../app/webroot/index.php/Users/add"
After hitting submit, it redirects me to this url (with the additional "Users" string) and with an error message.
".../app/webroot/index.php/Users/Users/add"
Missing Method in UsersController
Error: The action Users is not defined in controller UsersController
Error: Create UsersController::Users() in file: app/Controller/UsersController.php.
class UsersController extends AppController {
public function Users() {
}
}
Let me know where I should start checking, Thanks.
AppController
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
'authorize' => array('Controller') // Added this line
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
public function isAuthorized($user) {
// Admin can access every action
if (isset($user['role']) && $user['role'] === 'admin') {
return true;
}
// Default deny
return false;
}
}
Because I still can't comment, I'll tell you here and edit this answer if I know it.
Show me your AuthComponent configuration in AppController.php.
EDIT:
Answer is in the comments below. :)

cake php default routing not work

I want to define master routing for cakephp somthing like this.
Router::connect('/:lang/:plugins/:controller/:action/*', array('lang' => 'eng', 'controller' => 'index', 'action' => 'index', 'plugin' => null), array('lang' => '[a-z]{3}'));
but default not works. when i type these errors disappear:
/ Error: Controller could not be found.
/eng Error: EngController could not be found.
/eng/pages Error: EngController could not be found.
What the route errors are saying is that the controller that you're asking it to use doesn't exist. I'm assuming you're using CakePHP 2, so make sure your controller filename is like this:
EngController.php
And inside that controller file it is similar to this:
<?php
App::uses('AppController', 'Controller');
/**
* Eng Controller
*
*/
class EngController extends AppController {
/**
* Scaffold
*
* #var mixed
*/
public $scaffold;
}
EDIT:
I had another look at the route, and you have 'lang' => 'eng' at the start of the route. The errors you're getting are from the route thinking that eng is a controller. Remove this section altogether and it should fix it.

Resources