ah, what the heck. I figure the code says more than a thousand words…
in the controller I render the index
public function actionIndex() {
$this->render('index');
}
index.php looks like this:
$tabs = array(
'tab1' => array(
'title' => 'Alle Personen',
'list' => '/person/list',
'data' => array(
'model'=>'Person',
'condition'=>'deleted=0',
'order'=>'last_name',
),
),
'tab2' => array(
'title' => 'Ordentliche Mitglieder',
'list' => '/person/list',
'data' => array(
'model'=>'Person',
'condition'=>'deleted=0 AND type_membership="O"',
'order'=>'last_name',
),
),
'tab3' => array(
'title' => 'Firmenmitglieder',
'list' => '/person/list',
'data' => array(
'model'=>'Person',
'condition'=>'deleted=0 AND type_membership="F"',
'order'=>'last_name',
),
),
'tab4' => array(
'title' => 'Studenten',
'list' => '/person/list',
'data' => array(
'model'=>'Person',
'condition'=>'deleted=0 AND type_membership="S"',
'order'=>'last_name',
),
),
);
$this->widget('CustomTabView', array(
'tabs' => $tabs,
'viewData' => $data,
));
The modified TabView has this renderBody
protected function renderBody() {
foreach($this->tabs as $id=>$tab)
{
$inactive=$id!==$this->activeTab?' style="display:none"' : '';
echo "<div class="view" id="{$id}"{$inactive}>n";
if(isset($tab['content']))
echo $tab['content'];
else if(isset($tab['view'])) {
$this->viewData['tab'] = $id;
$this->getController()->renderPartial($tab['view'],$this->viewData);
} else if (isset($tab['list'])) {
$criteria=new CDbCriteria;
$criteria->order = $tab['data']['order'];
$criteria->condition = $tab['data']['condition'];
$pages=new CPagination(Person::model()->count($criteria));
$pages->pageSize = 20;
$pages->applyLimit($criteria);
$personList=Person::model()->with('email')->findAll($criteria);
$this->viewData['pages'] = $pages;
$this->viewData['personList'] = $personList;
$this->getController()->renderPartial('list', $this->viewData);
}
echo "</div><!-- {$id} -->n";
}
}
which brings us back to the controller, actually the list action
public function actionList($options=null)
{
$criteria=new CDbCriteria;
$criteria->order = 'last_name';
$criteria->condition = 'deleted=0';
$pages=new CPagination(Person::model()->count());
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$personList=Person::model()->with('email')->findAll($criteria);
$this->render('list',array(
'personList'=>$personList,
'emails'=>$personList->email,
'kategorie'=>$personList->kategorie,
'pages'=>$pages,
));
}
Now I want some kind of link or button, that can tell my export action what to do.
public function actionExport() {
$criteria = new CDbCriteria;
$sort = new CSort('Person');
$sort->applyOrder($criteria);
$people = Person::model()->findAll($criteria);
$export = new Export($people);
$export->outputCSV();
}
please help… 