[eluser]xpix[/eluser]
Hi,
I would like to know how can I simplify my code.
I have a backend section of the website. The controller backend.php has the following structure
Code:
class Backend extends Controller {
function Backend()
{
parent::Controller();
if(!$this->session->userdata('id')) {
redirect('admin');
}
$this->css = $this->config->item('css_path');
$this->jquery = $this->config->item('jquery');
}
function index()
{
$data['css'] = base_url().$this->css;
$data['links'] = $this->_links();
$this->load->view('backend',$data);
}
function segments($action = '', $id=''){
$data['css'] = base_url().$this->css;
$data['jquery'] = $this->jquery;
$data['links'] = $this->_links();
.... tons of code ....
$this->load->view('segments',$data);
}
function editsegment($id){
$this->segments('edit', $id);
}
function deletesegment($id){
$this->segments('delete', $id);
}
function subitems($action = '', $id=''){
$data['css'] = base_url().$this->css;
$data['jquery'] = $this->jquery;
$data['links'] = $this->_links();
.... tons of code ....
$this->load->view('subitems',$data);
}
function editsubitem($id){
$this->subitems('edit', $id);
}
function deletesubitem($id){
$this->subitems('delete', $id);
}
function logout()
{
$this->session->sess_destroy();
redirect('admin');
}
function _links(){
$list = array(
anchor('backend', 'Home'),
anchor('backend/segments', 'Segments'),
anchor('backend/subitems', 'Subitems'),
anchor('backend/logout', 'Log Out'),
);
$attributes = array('id' => 'links');
$links = ul($list, $attributes);
return $links;
}
}
For now there are only 2 sections of the website: segments and subitems. Even so there is to much code for one file.
How can I modify the code so "segments" has it's own file/controller and subitems another file/controller? Also I want for the URI to be the same Eg: backend/segments.
Also it seems that for every view I need to use the following:
$data['css'] = base_url().$this->css;
$data['jquery'] = $this->jquery;
$data['links'] = $this->_links();
inside the function
How can I make the above information visible from every view?
Thx