I have two modules (group and pages) which have a news section. The model is the same but with some changes in views and controllers. My structure is as follows
/ modules / groups / controllers / NewsController.php
/ modules / pages / controllers / NewsController.php
/ modules / groups / models / NewsGroup.php (extend models/News.php)
/ modules / pages / models / NewsPage.php (extend models/News.php)
I Have the views, behaviors and widgets in:
/ components / news /
and reuse them in the two modules.
/modules/groups/NewsController.php
...
public function actionCreate()
{
if (!Yii::app()->user->checkAccess("groups.createNews"))
$this->accessDenied();
$news=new NewsGroup();
if(isset($_POST['NewsGroup']))
{
$news->attributes=$_POST['NewsGroup'];
if($this->group->addNews($news))
$this->redirect($news->getUrl($this->group));
}
$this->render('application.components.news.views.create',array(
'model'=>$news,
//Specific view block for groups /modules/groups/views/news/_permissions.php
'permissions_view'=>$this->renderPartial('_permissions', array('model'=>$news), true)
));
}
...
/modules/pages/NewsController.php
...
public function actionCreate()
{
if (!Yii::app()->user->checkAccess("pages.createNews"))
$this->accessDenied();
$news=new NewsPage();
if(isset($_POST['NewsPage']))
{
$news->attributes=$_POST['NewsPage'];
if($this->page->addNews($news))
$this->redirect($news->getUrl($this->page));
}
$this->render('application.components.news.views.create',array(
'model'=>$news,
//Specific view block for pages /modules/pages/views/news/_permissions.php
'permissions_view'=>$this->renderPartial('_permissions', array('model'=>$news), true)
));
}
...
Is this the right way?, Is it better to repeat the code in views?
or How do you implement a news section in two different modules?
or Do you know any example code of how to implement a news(or another) section in two different modules?
Thanks.