Reputation: 654
i have a module that have different render with different conditions so i have used like
if($p_id != '') {
$this->render('view', array(
'model' => $this->loadModel($id, 'Supplier'),
'modeln' => $this->loadModel($p_id, 'Permit'),
));
} else {
$this->render('view', array(
'model' => $this->loadModel($id, 'Supplier'),
));
it works fine but i have 5 to 6 conditions like this ,so how can i handle this? any easy way than this? thanks
Upvotes: 1
Views: 133
Reputation: 1583
There are several approaches.
Make $p_id and view name more meaning ful. Or even, as:
$views = array(
'p_id' => 'corresponding_view file'
);
And then later, use it as $this->loadModel($p_id, $views[$p_id])
,
Upvotes: 2
Reputation: 8043
There are two solutions for this problem:
Adding condition inside controller and rendering multiple views based on condition.(As you do)
Having just one view and adding condition inside the view and showing desired parts of view based on condition.
All these two solution is achievable, But I believe first solution is better. Because second solution has inconsistency with MVC structure. It's not a good idea to put logic inside the view. So I think rendering different views based on condition is better.
Upvotes: 0