1

I am currently developing a Lithium application and have come across a function that I have written that I would like to use across multiple Controllers.

I obviously don't want to have the function in each controller. What is the standard way of creating a re-usable component in Lithium?

The lack of search facility on their documentation is making it difficult to find any specifics.

GaryDevenay
  • 2,405
  • 2
  • 19
  • 41

3 Answers3

2

You could try extending controller. Extending controllers is not that bad according to core devs. If that is not and option you could extract your code into a plugin, still some code in controller though.

Marius
  • 185
  • 11
2

All you have to do is create a extensions/action/Controller.php and have your controllers extend that.

In your extensions/action/Controller.php

<?php
namespace app\extensions\action;

class Controller extends \lithium\action\Controller {

    protected function _init() {
        parent::_init();

        //add your functionality here
    }
}

?>

And then, your controller has to extend the above mentioned base controller: class MyController extends \app\extensions\action\Controller {

Housni
  • 963
  • 1
  • 10
  • 23
0

I think this is not a Lithium-specific thing. You could either inherit from the Controller and make your own base controller, but you can also create arbitrary classes that hold your functionality. Don't let a framework inhibit you =)

Regarding the documentation: I usually google in the sense of "<keywords> site:lithify.me"

Tomen
  • 4,854
  • 5
  • 28
  • 39