私はCodeIgniterの初心者ですが、続行していると、手続き型コーディングで簡単に修正できる問題が発生します。
現在の問題は次のとおりです:私はこのコントローラーを持っています
class Basic extends Controller {
function index(){
$data['title'] = 'Page Title';
$data['robots'] = 'noindex,nofollow';
$data['css'] = $this->config->item('css');
$data['my_data'] = 'Some chunk of text';
$this->load->view('basic_view', $data);
}
function form(){
$data['title'] = 'Page Title';
$data['robots'] = 'noindex,nofollow';
$data['css'] = $this->config->item('css');
$data['my_other_data'] = 'Another chunk of text';
$this->load->view('form_view', $data);
}
}
ご覧のとおり、一部の配列項目は何度も繰り返されます。
$data['title'] = 'Page Title';
$data['robots'] = 'noindex,nofollow';
$data['css'] = $this->config->item('css');
それらをコントローラーで「グローバル」にして、関数ごとに入力する必要がないようにする方法はありませんか?のようなもの(しかし、これは私にエラーを与えます):
class Basic extends Controller {
// "global" items in the $data array
$data['title'] = 'Page Title';
$data['robots'] = 'noindex,nofollow';
$data['css'] = $this->config->item('css');
function index(){
$data['my_data'] = 'Some chunk of text';
$this->load->view('basic_view', $data);
}
function form(){
$data['my_other_data'] = 'Another chunk of text';
$this->load->view('form_view', $data);
}
}
事前にThnaks!