Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Global Usage of Lang Files
  • I'd like to be able to reuse my lang files throughout all of the methods in a class, instead of needing to respecify. Seems redundant. Example (what I don't like): public function action_index()
    {
    Lang::load('admin/solutions', 'solutions');
    } public function action_add()
    {
    Lang::load('admin/solutions', 'solutions');
    } I tried using a constructor method, but that broke the app: ErrorException [ Error ]: Call to a member function body() on a non-object
    COREPATH/classes/controller/template.php @ line 56 So...I tried before() function But then my variables weren't available in other methods. Anyone have a suggestion?
  • Calvin Froedge wrote on Friday 17th of June 2011:
    So...I tried before() function But then my variables weren't available in other methods. Anyone have a suggestion?

    What do you mean with "my variables weren't available in other methods"? In before() put Lang::load(...);
    And in other methods use Lang::Line(...) ... where is the problem?
  • class MyClass
    {
    public function before()
    {
    Lang::load('admin/solutions', 'solutions');
    } public function action_index()
    {
    $this->template->title = Lang::line('solutions.title');
    }
    } Does not work... class MyClass
    {
    public function action_index()
    {
    Lang::load('admin/solutions', 'solutions');
    $this->template->title = Lang::line('solutions.title');
    }
    } Works... I dunno?
  • If it's a random class and not a controller the method used must be _init(), the before() method only works with Controllers and ViewModels. _init() is like a constructor (__construct()) and is executed by Fuel automaticly when the class is loaded (contrary to __construct() which is executed each time you create an object of the class).
  • It was a controller, but was extending a base controller which extended the controller_template. Your suggestion to use _init worked. Thanks, Jelmer!

Howdy, Stranger!

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

In this Discussion