この解決策を回避する方法はいくつかありますが、問題の規模によって異なります。
より良い解決策は、次のようなものかもしれません。
意見
<?php echo $conditional_html; ?>
コントローラ
switch($pageID)
{
case 1:
$data['conditional_html'] = $this->load->view('the_first_id_html', TRUE);
break;
case 4:
case 7:
case 8:
$data['conditional_html'] = $this->load->view('some_special_html', TRUE);
break;
case 13:
case 18:
$data['conditional_html'] = $this->load->view('the_secret_menu_html', TRUE);
break;
default:
$data['conditional_html'] = $this->load->view('the_default_html', TRUE);
}
$this->load->vars($data);
ビュー内にビューをロードすることを気にしない場合は、別の簡単な方法で次のようにすることができます。
意見
<?php $this->load->view($conditional_html); ?>
コントローラ
switch($pageID)
{
case 1:
$data['conditional_html'] = 'the_first_id_html';
break;
case 4:
case 7:
case 8:
$data['conditional_html'] = 'some_special_html';
break;
case 13:
case 18:
$data['conditional_html'] = 'the_secret_menu_html';
break;
default:
$data['conditional_html'] = 'the_default_html':
}
$this->load->vars($data);
最終的には、さまざまな方法でこれを行うことができますが、これが別の方法に光を当てられることを願っています.