[英]Access Model Methods with Zend
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. 我发现第二种方法更快速,更容易阅读,我必须做些什么才能使其起作用,我已经尝试过了,但是不起作用。
To achieve your goal, you have to declare the getContact()
method as static
. 为了实现您的目标,必须将
getContact()
方法声明为static
。 Anyway you should declare a static method only when it has sense, not just because of a "more readable" code. 无论如何,您仅应在有意义的情况下声明静态方法,而不仅仅是因为“更具可读性”的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.