Custom view helper and auto detecting directory

View: New views
2 Messages — Rating Filter:   Alert me  

Custom view helper and auto detecting directory

by rcastley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
 
This is probably more of a PHP than ZF question, but I am hoping some can help :-)
 
I have a custom view helper class for widgets that live outside the MVC structure i.e.
 
htdocs
  application
    controllers
    models
    views
    ...
  library
    Magik
      View
        Helper
          WidgetMessage.php
      View.php
    ...
   widgets
     MyWidget
       MyWidget.php
       MyWidget.phtml
       
 
<code>
class Magik_View extends Zend_View
{
    public function __construct($path = null)
    {
        $this->addHelperPath('library' . DS . 'Magik' . DS . 'View' . DS . 'Helper' , 'Magik_View_Helper'
);

        $this->setScriptPath($path);
    }

}
</code>

As you can see in the above code I have to pass a path when I call the class within my file MyWidget.php e.g.

$view = new Magik_View(dirname(__FILE__));

What I would like to be able to do is just use:

$view = new Magik_View();

So, my question is, is there anyway for my custom view helpler to be able to automatically detect the directory that MyWidget.php is living in?

Thanks in advance,

- Robert


________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email Security Service and the Macro 4 plc internal virus protection system.
________________________________________________________________________

Parent Message unknown RE: Custom view helper and auto detecting directory

by rcastley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think I have found a better way to ask my question:
 
Is there anyway you can find out which file created an instance of you class?


From: Robert Castley
Sent: 08 May 2008 12:47
To: fw-general@...
Subject: [fw-general] Custom view helper and auto detecting directory

Hi,
 
This is probably more of a PHP than ZF question, but I am hoping some can help :-)
 
I have a custom view helper class for widgets that live outside the MVC structure i.e.
 
htdocs
  application
    controllers
    models
    views
    ...
  library
    Magik
      View
        Helper
          WidgetMessage.php
      View.php
    ...
   widgets
     MyWidget
       MyWidget.php
       MyWidget.phtml
       
 
<code>
class Magik_View extends Zend_View
{
    public function __construct($path = null)
    {
        $this->addHelperPath('library' . DS . 'Magik' . DS . 'View' . DS . 'Helper' , 'Magik_View_Helper'
);

        $this->setScriptPath($path);
    }

}
</code>

As you can see in the above code I have to pass a path when I call the class within my file MyWidget.php e.g.

$view = new Magik_View(dirname(__FILE__));

What I would like to be able to do is just use:

$view = new Magik_View();

So, my question is, is there anyway for my custom view helpler to be able to automatically detect the directory that MyWidget.php is living in?

Thanks in advance,

- Robert


________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email Security Service and the Macro 4 plc internal virus protection system.
________________________________________________________________________

________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email Security Service and the Macro 4 plc internal virus protection system.
________________________________________________________________________

________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email Security Service and the Macro 4 plc internal virus protection system.
________________________________________________________________________