SolarPHP How to use unlimited functions in a View Helper

I was chatting on irc with dmytrok (kudos to him about the tip below) about the Solar View Helpers and it seems there's a very simple way of using multiple functions in a solar view helper.

As you know, for creating a Solar View Helper you create a class like:

  1. class Vendor_View_Helper_MyTest extends Solar_View_Helper {
  2.  
  3.     public function myTest()
  4.     {
  5.         // logic here
  6.     }
  7. }

And then you can call it in your views by using $this->myTest() and all will go well.

For having multiple functions in that helper you must make it return the $this object so you can access the inside functions.

  1. class Vendor_View_Helper_MyTest extends Solar_View_Helper {
  2.  
  3.     public function myTest()
  4.     {
  5.         return $this;
  6.     }
  7.  
  8.     public function Inside()
  9.     {
  10.        //logic here
  11.     }
  12. }

Now you can access any function side the myTest helper like

  1.     $this->myTest()->Inside();

Add new comment