#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,664
    Rep Power
    171

    On mvc. How to load multiple sets of dynamic data? One controller or more?


    If my page loads 20 different unrelated dynamic quires from the database, how should I structure my controller(s) (example below)? Specially with the way the URL is set up http://localhost/site/Controller/Method/Arg looks like I can only load 1 controller in a page!!!!!!!! What part I'm not getting?
    1 - A query loads a list of members.
    2 - A query shows search results (on the right column).
    3 - A query shows list of something totally unrelated (hotels).
    .
    .
    .
    20 - A query shows list of something totally unrelated (pink elephants).
    My code:
    PHP Code:
    //As you can see this controller is only for members. 
    //Maybe I should call different controllers somehow! But how? //Who knows? Maybe E-oreo 
    class Members extends CI_Controller {
        public 
    $member_id;
        

        public function 
    index()    
            {
                
    $page_info['title'] = "Members Page";
                
    $this->load->view('header_view'$page_info);
                
    $this->load->model('members_model');
                
    $results $this->members_model->get_all_members();
                
    $all_members['all']=$results ;
                
    $this->load->view('members_view'$all_members);
            } 
    Thanks
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,066
    Rep Power
    9398
    Controllers are for pages, not for data. One controller for the homepage and it can put lots of assorted data into the view.
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,664
    Rep Power
    171
    Originally Posted by requinix
    Controllers are for pages, not for data. One controller for the homepage and it can put lots of assorted data into the view.
    I have multiple functions in my controller and each of them send different values to view. I was wondering how I can send values from different functions of a controller to a view which already has been loaded “WITHOUT RELOADING IT”. In other words, I do not want to load a view multiple times, I just want to load it once, and further send values to it from different functions.
    PHP Code:
    public function __construct()
         {
      
    //Load header
            
    $page_info['title'] = "Members";
      
    $this->load->view('header_view'$page_info);
      }

    public function 
    show_members()
         {
      
    //Load view and send member's info
      
    $this->load->model('members_model');
      
    $data $this->members_model->search();
      
    $m['members'] = $data;
      
    $this->load->view('members_view'$m)
    }
    public function 
    show_bookings()
     {
      
    //Load view and send bookins's info
      
    $this->load->model('bookings_model');
      
    $data $this->bookings_model->search();
      
    $b['members'] = $data;
      
    $this->load->view('members_view'$b//But as you see here, the view has already been loaded. I dont want to re-load it, I just want to send data to it.
     

    Perhaps I should have lots of views for everything.
    Thanks
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,066
    Rep Power
    9398
    Sounds like your design isn't suitable for your needs.
  8. #5
  9. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,664
    Rep Power
    171
    Originally Posted by requinix
    Sounds like your design isn't suitable for your needs.
    I ended up with what I wanted. It does exactlly what I wanted. What do you think?
    PHP Code:
    class Members extends CI_Controller {
        public 
    $member_id;
        
        public function 
    __construct()    
            {
                
    parent::__construct();
                
    $data['title'] = "Members Page";
                
    $this->load->vars($data);
                
    $this->members();
                
    $this->places();
                
    $this->view();
            }
        public function 
    index()
            {
                
            }

        public function 
    members()    
            {
                
    $this->load->model('members_model');
                
    $data['members'] = $this->members_model->get_all_members();
                
    $this->load->vars($data);
            }
            
        public function 
    places()
            {
                
    $this->load->model('places_model');
                 
    $data['places'] = $this->places_model->get_all_places();
                 
    $this->load->vars($data);
                 
    //$this->output->enable_profiler(TRUE);
             
    }
         public function 
    view()
             {
                 
    $this->load->view('header_view');
                 
    $this->load->view('members_view');
                 
    $this->load->view('footer_view');
             } 
    Last edited by zxcvbnm; November 1st, 2012 at 01:47 AM.

IMN logo majestic logo threadwatch logo seochat tools logo