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 *
Related
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) ));
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'
),
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');
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. :)
After migrating a fully functional Cake 1.3 application to the recently released 2.0 version Authentication has ceased to work.
I've changed the calling of the AuthComponent and the structure of the login action according to the updated 2.0 manual, to no avail. The strange thing is the user is actually validated by $this->Auth->login() as it reaches the part of the login function where the user is redirect to the url set by $this->Auth->redirect(). After that redirect however, $this->Auth->user() returns empty (as well as AuthComponent::user()) and the user isn't logged in by the Auth component.
Cake doesn't throw any error during the process, the flash messages for 'auth' remain empty.
Users are stored in a simple database table containing id, username, email, password and timestamp columns. The passwords are hashed and I've added some users using the new Cake 2.0 methods.
This is the code of AppController.php:
<?php
class AppController extends Controller {
public $helpers = array('Session', 'Html', 'Time', 'Form', 'Text');
public $components = array('Session', 'RequestHandler', 'Auth');
public function beforeFilter() {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'maps', 'action' => 'index');
$this->Auth->logoutRedirect = array('controller' => 'maps', 'action' => 'index');
}
}
?>
UserController.php:
<?php
class UsersController extends AppController {
public $name = 'Users';
function beforeFilter() {
parent::beforeFilter();
}
function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
}
}
function logout() {
$this->redirect($this->Auth->logout());
}
}
?>
User.php model. I've disabled form validation for the time being after I solve this problem:
<?php
class User extends AppModel {
public $name = 'User';
}
?>
The login view:
<?php
echo $this->Form->create('User');
echo $this->Form->input('username', array('label' => 'Username', 'before' => '<p class="input" id="username">', 'after' => '</p>', 'between' => '<br />', 'div' => false));
echo $this->Form->input('password', array('label' => 'Password', 'before' => '<p class="input" id="password">', 'after' => '</p>', 'between' => '<br />', 'div' => false));
echo $this->Form->end('Login');
?>
I also tried to setting some of the Auth features in the $components variable in the AppController, which didn't work as well:
public $components = array(
'Auth'=> array(
'loginAction' => array(
'controller' => 'users',
'action' => 'login',
),
'loginRedirect' => array(
'controller' => 'maps',
'action' => 'index',
),
'authenticate' => array(
'Form' => array(
'fields' => array('username', 'password')
)
)
)
);
What's causing the problem here? Routing maybe? I've commented out all routes except:
require CAKE . 'Config' . DS . 'routes.php';
UPDATE:
After adding some debug statements in the login method in the UsersController I now know $this->Auth->user() is actually populated with the correct user after the call to $this->Auth->login(). After the redirect to another controller the login session is lost completely, however. So I still don't know what's going wrong here.
UPDATE 2
I've restarted the process of migrating by taking my working 1.3 application and running the migration console script on it like I did the last time.
This time I noticed the script stopped because of two errors relating to custom components. Component classes should extend Component now, instead of the 1.3 default: Object.
After fixing these component errors I ran the migration script again (something I neglected to do during the first migration attempt) and implemented the new AuthCompenent call. So far everything seems to be working correctly. Not sure what's different now and what went wrong the first time, as Cake didn't output any error messages.
UPDATE 3
It's getting weirder. I thought I solved it, but after transferring my code to another development machine Auth suddenly stops working. It's working on my main setup, but while testing on another it fails again following the same scenario. I've cleared the cache to be sure, but it still isn't working. Cake doesn't generate any error output.
UPDATE 4
It appears to be a Session problem on my machine. I've just set the Session to be stored in a cookie and suddenly Auth starts working again. Not sure why the default Session isn't working and I don't know where to start debugging in that case.
Only cookie sessions appear to work, defining a database session has the same result as a regular session; Auth stops working.
Try it with use_trans_sid enabled in /Config/core.php:
Configure::write('Session', array(
//'defaults' => 'php'
'defaults' => 'cake',
'cookie' => 'CAKEPHP2',
'ini' => array('session.use_trans_sid' => true)
));
Did you try also to configure the Authentication handler ?
public $components = array(
'Auth'=> array(
'authenticate' => array('Form')
)
);