Hector Virgen schreef:
I believe $view->render() will throw an exception if the view script could not be found. This may save you from having to run file_exists() and will automatically use the registered view script paths.
As far as the action is concerned, I think Mert is right, but there might be better ways.
Just curious -- why not store the actual information in the database? It would save you from writing tests if you knew how to call it.
--
Hector
On Thu, Sep 24, 2009 at 4:33 AM, Mert Oztekin <moztekin@anadolusigorta.com.tr> wrote:
May be it is the worst answer that can be given, but this should work : you can try method_exists() function to look if barAction exists in YourClass_Bar. And if false, you can check if 'bar.phtml' file exists with file_exists() function.
This should work. But there should be a much better answer.
Bu mesaj ve ekleri, mesajda g?nderildi?i belirtilen ki?i/ki?ilere ?zeldir ve gizlidir. Size yanl??l?kla ula?m??sa l?tfen g?nderen kisiyi bilgilendiriniz ve mesaj? sisteminizden siliniz. Mesaj ve eklerinin i?eri?i ile ilgili olarak ?irketimizin herhangi bir hukuki sorumlulu?u bulunmamaktad?r. ?irketimiz mesaj?n ve bilgilerinin size de?i?ikli?e u?rayarak veya ge? ula?mas?ndan, b?t?nl???n?n ve gizlili?inin korunamamas?ndan, vir?s i?ermesinden ve bilgisayar sisteminize verebilece?i herhangi bir zarardan sorumlu tutulamaz.
-----Original Message-----
From: Dimitri van Hees [mailto:dimitri@freshheads.com]
Sent: Thursday, September 24, 2009 2:29 PM
To: fw-mvc@lists.zend.com
Subject: [fw-mvc] how to check if action or partial exists?
Hi,
I am working on a view helper that loops through a set of given
controller/action values. The rank of this set can be modified by the
user (it's stored in the database). However, not everything needs to be
a 'real' action. It could also be a partial, like a single banner. I
would still like to use the same pairs of data, stating that if the
action 'bar' exists in controller 'foo', I am going to output
$this->view->action('bar','foo'). If it doesn't exist, I'd like to check
if there is a partial called 'foor/bar.phtml' and eventually output
$this->view->partial('foor/bar.phtml'). If this also doesn't exist, I'd
like to throw an exception.
However, I can't find any possibility to check whether a partial or an
action in a given controller exists (from within my view helper or
anywhere else). Can anyone tell me if this is possible at all, and if it
is, how? Thanks in advance!
Kind regards,
Dimitri van Hees
This message and attachments are confidential and intended for the individual(s) stated in this message. If you received this message in error, please immediately notify the sender and delete it from your system. Our company has no legal responsibility for the contents of the message and its attachments. Our company shall have no liability for any changes or late receiving, loss of integrity and confidentiality, viruses and any damages caused in anyway to your computer system.
没有评论:
发表评论