Welcome Guest, Not a member yet? Register   Sign In
Loading controllers from a view
#4

[eluser]pickupman[/eluser]
This is a good question actually. Part of the hard part is the learning curving coming over to PHP/CI and having to use object oriented programming.

Here's how I would use your code
Code:
function index(){
    $data['main_content'] = 'portfolio_home';

    $data['listProjects'] = $this->_listProjects(); //Run _listProjects method and save table to variable
    $this->load->view('portfolio',$data);
}

//This method/function could be put into a library/model as it is accessing DB
//Note the _ underscore this prevents the url being directly accessible
function _listProjects(){
    $this->load->library('table');
    
    //Use active record syntax for safer queries
    $this->db->select('clients.client, project_list.project, project_list.role, project_list.url');
    $this->db->from('clients, project_list');
    $this->db->where('clients.id', 'project_list.client_id');
    $this->db->group_by('clients.client, project_list.project');
    $query = $this->db->get();        
        
    return $this->table->generate($query);
}

When I first starting using CI, I had some big index() functions. You will find your code will be easier to manage if you can segment some of this code into libraries or other private methods in the controller.


Messages In This Thread
Loading controllers from a view - by El Forum - 11-23-2010, 07:40 AM
Loading controllers from a view - by El Forum - 11-23-2010, 07:47 AM
Loading controllers from a view - by El Forum - 11-23-2010, 07:53 AM
Loading controllers from a view - by El Forum - 11-23-2010, 08:04 AM
Loading controllers from a view - by El Forum - 11-23-2010, 08:43 AM
Loading controllers from a view - by El Forum - 11-23-2010, 09:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB