Re: Cake
| From: | Philip Thompson | Date: | Fri, 13 Aug 2010 17:14:39 +0000 |
| Subject: | Re: Cake | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-307437@lists.php.net to get a copy of this message | ||
On Aug 13, 2010, at 10:49 AM, Philip Thompson wrote:
> Hi all.
>
> Having an issue with some CakePHP 1.3 stuff. I've read and read and read and haven't
> found my solution. I'm fairly new to Cake, so be nice. I'm trying to access a method from
> a different controller than the one I'm in and it's not letting me.
>
> -location.php (model) - create the relationship
> public $belongsTo = 'Address';
>
> -locations_controller.php - grab all the locations (+ addresses for each location) and format
> the addresses
> $locations = $this->Location->find('all');
> ...
> $this->Location->Address->format(...); // This line throws the error
> ...
>
> -addresses_controller.php
> public function format (...) { ... }
>
> From my understanding, everything is defined correctly, but it thinks that I'm calling a
> query when it errors:
>
> Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use near 'format' at line
> 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 681]
>
> It thinks that the method "format()" is a query. Why?! I just want it to call that
> method. Please help!
>
> Thanks in advance,
> ~Philip
I'm sure this is a rookie mistake, but I figured it out. I was putting the format() method in
the addresses_controller file when I should have been putting it into the address model file. Upon
putting it there, it worked as expected!
Thanks!
~Philip