Perhaps I have a plural typo, but I'm not sure - because the call from
the model's own controller works - only if you call from a DIFFERENT
controller does it not work. Here's a test I did:

class Message extends AppModel {
    var $name = 'Message';
    function get_message() {
        $message = $this->find('first');
        return $message['Message']['title'];
    }
}

class MessagesController extends AppController {
    var $name = "Messages";
    function get_message() {
        $this->set( 'message', $this->Message->get_message() );
    }
}

And the view get_message.ctp is just: <?php echo $message ?>. If I
then go to /cake/messages/get_message then it works as expected: "TEST
MESSAGE! W00T!"

But if I then add another model:
class Test extends AppModel
{
    var $name = 'Test';
        var $useTable = false;
}

class TestsController extends AppController {
    var $name = "Tests";
    var $uses = array( 'Messages' );

    function get_message() {
        // Original way - works lovely.
        $message = $this->Messages->find('first');
        $this->set( 'fromFind', $message['Messages']['title'] );

        // "Fat Model" way - receives an exception.
        $this->set( 'fromModel', $this->Messages->get_message() );
    }
}
With the view: <?php echo $fromFind . ":" . $fromModel ?>

If I then go to /cake/tests/get_message then it outputs the $fromFind
variable, but crashes when trying to load the get_message() from the
Messages model:
"Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
etc... (as original exception)"

It's like cake can't see the custom method on the Message class from
outside it's own controller. Or I'm doing something stupid.


On Feb 19, 9:06 am, Adam Royle <[email protected]> wrote:
> Sounds like you have a typo somewhere (maybe you've got plural instead
> of singular?). Cake automatically creates models if they don't exist.
> Therefore it is creating a model (an instance of AppModel) and your
> method is not defined in AppModel.
>
> Make sense?
>
> Adam
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to