Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Own global php functions in views
  • Hello, Is there a way to create global php functions that are accessible in views? Thanks.
  • Justin Kouwenhoven wrote on Tuesday 28th of June 2011:
    Hello, Is there a way to create global php functions that are accessible in views? Thanks.

    Yes, here's an example. place the file in app/classes/helper.php
    class Helper {
    
        public static function  method($var){
        return $var;
        }
    }
    

    Then in your view you can do this.
    <?php \helper::method('hello!');?>
    

    Make sure you have the \ front of the class name otherwise you may get an error trying to call it from some places.
  • Thank you for your help.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion