www.webdeveloper.com
Results 1 to 5 of 5

Thread: CakePHP giving me missing action message

  1. #1
    Join Date
    Aug 2007
    Location
    London
    Posts
    410

    CakePHP giving me missing action message

    Hi all,

    I'm trying to define the following action "validate" for the controller "ProjectsController" but for some reason cake is throwing a wobbly.

    PHP Code:
    class ProjectsController extends AppController {
        var 
    $name "Projects";

        
    //... some other actions which all work


        
    function validate($what) {
            
    $this->layout "ajax";
            
            switch(
    $what) {
                case 
    "title":
                    
    $count $this->Project->find("count", array("conditions"=>array("title"=>$this->data["data"])));
                    
    $this->set("isValid", ( ($count == 0) ? true false ));
                    
    $this->set("message", ( ($count == 0) ? "" "A project with this title already exists." ));
                    break;
                default:
                    
    $this->set("isValid"false);
                    
    $this->set("message""No validation rules exist for $what.");
            }
        }

    Even if I make the action completely empty:
    PHP Code:
    function validate() {


    Cake is still giving me:
    HTML Code:
    Missing Method in ProjectsController
    Error: The action validate is not defined in controller ProjectsController
    Error: Create ProjectsController::validate() in file: app/controllers/projects_controller.php.
    <?php
    class ProjectsController extends AppController {
    
    	var $name = 'Projects';
    
    
    	function validate() {
    
    	}
    
    }
    ?>
    Does anyone have any idea why this is?
    Last edited by blue-eye-labs; 04-04-2010 at 07:35 AM. Reason: appcontroller not model

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    Probably to do with the fact you are extending your controller from AppModel instead of AppController

    BTW just a general tip, if you use the RequestHandler component, Cake will automatically render your ajax views within your ajax layout when it detects an ajax request, so you don't need to modify your action in any way. If you configure the router to parse extensions you can extend this further still - for instance I typically have RequestHandler parse .json and .rss extensions - that way I use the exact same controller/action code, but depending on the request type and extension cake automatically renders either /controller/view.ctp, /controller/ajax/view.ctp, /controller/json/view.ctp or /controller/rss/view.ctp - and it also loads their corresponding layout, eg /layouts/ajax/default.ctp.
    The first rule of Tautology Club is the first rule of Tautology Club.

  3. #3
    Join Date
    Aug 2007
    Location
    London
    Posts
    410
    Sorry, that was a typo, it wasn't copied directly. I'll change it.
    Thanks for the tip.

    So any ideas why it isn't working?

  4. #4
    Join Date
    Nov 2008
    Posts
    2,477
    Controller already has a method named validate, and your AppController extends Controller, and this controller in turn extends AppController. You will need to change the name of the action. If you want to still use /projects/validate as a URL, add the following to app/config/routes.php:

    PHP Code:
    Router::connect('/projects/validate/*', array('controller' => 'projects''action' => 'renamed_validate_action')); 
    The first rule of Tautology Club is the first rule of Tautology Club.

  5. #5
    Join Date
    Aug 2007
    Location
    London
    Posts
    410
    Quote Originally Posted by Mindzai View Post
    Controller already has a method named validate, and your AppController extends Controller, and this controller in turn extends AppController. You will need to change the name of the action. If you want to still use /projects/validate as a URL, add the following to app/config/routes.php:

    PHP Code:
    Router::connect('/projects/validate/*', array('controller' => 'projects''action' => 'renamed_validate_action')); 
    Okay, brilliant. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles