Ahhh... the line I had in test_controller:
var $uses = array( 'Messages' );
just imports the Messages CONTROLLER, not the MODEL (is that right?!).
To get it to work I had to change it to
var $uses = array( 'Message' ); // Message, not Messages
and then change my index function to:
function index() {
$message = new Message(); // need to add this constructor!
$this->set( 'message', $message->get_welcome_message() );
}
Which looks a bit more messy than I'd like - but I think it's just
because i haven't set up my associations correctly yet.
On Feb 19, 9:40 am, Mr Speaker <[email protected]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---