質問

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.

役に立ちましたか?

解決

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.

他のヒント

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 {

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"

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top