Take the 2-minute tour ×

This is how I've been accessing model methods from my controllers:

$contactsTable = new Application_Model_DbTable_ContactsBasics();
$contact = $basicsTable->getContact($contacts_id);

How can I do the same by doing it like this?

$contact = Application_Model_DbTable_ContactsBasics::getContact($contacts_id);

I find the second way a little faster and easier to read, what do I have to do make it work, I already tried it but It doesn't work.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

To achieve your goal, you have to declare the getContact() method as static. Anyway you should declare a static method only when it has sense, not just because of a "more readable" code.

share|improve this answer
Thank you for poiting in me in the right direction, I read up on static methods and I came across this: Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside the method declared as static. I won't be using static methods because I use the $this variable a lot in my models. –  MikeGA Jan 12 '12 at 0:02
You can check if you can replace $this by 'self' –  BartekR Jan 13 '12 at 7:34
add comment

Your Answer


