missing controller error in cakephp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

missing controller error in cakephp

Rajesh Vishnani

I am simply doing login and registration of users in cake php, here is my file structure!

app/controller/users_controller.php

<?php
    class UsersController extends AppController {

        public function beforeFilter() {
            parent::beforeFilter();
            $this->Auth->allow('add');  
        }
        public function add() {
            if(!empty($this->data)) {
                $this->User->create();
                if($this->User->save($this->data)) {
                    $this->Session->SetFlash('User Created!');
                    $this->redirect(array('action'=>'login'));
                }
                else {
                    $this->Session->SetFlash('Please correct the errors!');
                }
            }
        }
        public function login() {

        }
        public function logout() {
            $this->redirect($this->Auth->logout());
        }
    }
?>

app/app_controller.php

<?php
    class AppController extends Controller {
        public $components = array(
            'Auth' => array(
            'authorize'=>'controller'
            ),
            'Session'
            );
        public function isAuthorized() {
            return true;
        }
    }
?>

app/View/users/login.ctp

<?php
    echo $this->Form->create(array('action'=>'login'));
    echo $this->Form->inputs(array('legend'=>'Login','username','password'));
    echo $this->Form->end('Login');
?>

app/View/users/add.ctp

<?php
    echo $this->Form->create();
    echo $this->Form->inputs(array(
        'legends' => 'Signup',
        'username',
        'password'));
    echo $this->Form->end('Submit');
?>

and i am browsing below URL

www.abc.com/../cakephp/users/add

i get below erros

Error: UsersController could not be found.

Error: Create the class UsersController below in file: app/Controller/UsersController.php

<?php
class UsersController extends AppController {

}

Notice: If you want to customize this error message, create app/View/Errors/missing_controller.ctp

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: missing controller error in cakephp

Andras Kende
In cakephp 2+ filenames are CamelCased so rename

> app/controller/users_controller.php
> to
> app/Controller/UsersController.php
>
> app/app_controller.php
> to
> app/Controller/AppController.php

also:

> app/View/users/login.ctp
to
app/View/Users/login.ctp

etc..

Andras Kende
http://www,kende.com


On Dec 7, 2013, at 4:17 AM, Rajesh Vishnani <[hidden email]> wrote:

> I am simply doing login and registration of users in cake php, here is my file structure!
>
> app/controller/users_controller.php
>
> <?
> php
>    
> class UsersController extends AppController {
>
>
>        
> public function beforeFilter() {
>
>             parent
> ::beforeFilter();
>
>             $this
> ->Auth->allow('add');
>  
>        
> }
>
>        
> public function add() {
>
>            
> if(!empty($this->data)) {
>
>                 $this
> ->User->create();
>
>                
> if($this->User->save($this->data)) {
>
>                     $this
> ->Session->SetFlash('User Created!');
>
>                     $this
> ->redirect(array('action'=>'login'));
>
>                
> }
>
>                
> else {
>
>                     $this
> ->Session->SetFlash('Please correct the errors!');
>
>                
> }
>
>            
> }
>
>        
> }
>
>        
> public function login() {
>
>
>        
> }
>
>        
> public function logout() {
>
>             $this
> ->redirect($this->Auth->logout());
>
>        
> }
>
>    
> }
> ?>
> app/app_controller.php
>
> <?
> php
>    
> class AppController extends Controller {
>
>        
> public $components = array(
>
>            
> 'Auth' => array(
>
>            
> 'authorize'=>'controller'
>
>            
> ),
>
>            
> 'Session'
>
>            
> );
>
>        
> public function isAuthorized() {
>
>            
> return true;
>
>        
> }
>
>    
> }
> ?>
> app/View/users/login.ctp
>
> <?
> php
>     echo $this
> ->Form->create(array('action'=>'login'));
>
>     echo $this
> ->Form->inputs(array('legend'=>'Login','username','password'));
>
>     echo $this
> ->Form->end('Login');
> ?>
> app/View/users/add.ctp
>
> <?
> php
>     echo $this
> ->Form->create();
>
>     echo $this
> ->Form->inputs(array(
>
>        
> 'legends' => 'Signup',
>
>        
> 'username',
>
>        
> 'password'));
>
>     echo $this
> ->Form->end('Submit');
> ?>
> and i am browsing below URL
>
> www.abc.com/../cakephp/users/add
>
> i get below erros
>
> Error: UsersController could not be found.
>
> Error: Create the class UsersController below in file: app/Controller/UsersController.php
>
> <?
> php
>
> class UsersController extends AppController {
>
>
>
> }
> Notice: If you want to customize this error message, create app/View/Errors/missing_controller.ctp
>
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>  
> ---
> You received this message because you are subscribed to the Google Groups "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/groups/opt_out.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.