如何为多个模块使用创建Yii模块/组件/扩展?

I'm creating a YII application containing multiple modules. Each module contains a FrontendController and a BackendController.

Now I have functionality shared by all of these modules, like a customizable Facebook share button. The share button should have a text and a title which can be edited inside the backend. And then is displayed in the module frontend.

The best scenario would be adding two lines to each controller, resulting in another settings tab in the backend and rendering a share button inside the frontend.

I've looked into PHP Traits which could add the functionality to the controllers, but I still need extra models, etc.

You should take advantage of the so called Application Components for the high level programming. This is the way to separate the logic in a class that extends CApplicationComponent and to include that component to both Front and Backend Controllers.

API: http://www.yiiframework.com/doc/api/1.1/CApplicationComponent

Sample component: http://www.yiiframework.com/wiki/187/how-to-write-a-simple-application-component

In the case of html re-usage for customizable Facebook share button you can just use a CWidget class and include that one in the views. This is the most native way of html code re-usage.

API: http://www.yiiframework.com/doc/api/1.1/CWidget

Sample widget: http://www.yiiframework.com/wiki/310/simple-share-widget-for-facebook-twitter-and-google

Here's how you can use the widget:

<?php
$this->widget('SimpleShare', array(
    'pageTitle' => 'The title of the page.',
    'pageDescription' => 'The long descriptions of the page.',
));
?>