I'm a very newbie on CodeIgniter, and while I go on I run into problems that, in the procedural coding, were easy to fix
The current issue is: I have this controller
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);
}
}
As you can see, some array items repeat over and over:
$data['title'] = 'Page Title';
$data['robots'] = 'noindex,nofollow';
$data['css'] = $this->config->item('css');
Isn't there a way to make them "global" in the controller, so that I have not to type them for each function? Something like (but this gives me error):
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 in advance!