#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,156
    Rep Power
    220

    Is it bad practise to load data like this?


    Hey I am shrinking the code so instead of several controllers only use one. Also basing a big product launch on this, just making sure it's reliable.

    Using Devshed discussion board, I wanna make sure not messing anything up.

    Are there any potential serious issues here?

    A few things:

    1. Just pretending. I never knew and still don't know the difference between protected and private.
    2. The way I deal with errors is gonna provoke some emotions I am sure.
    3. Thoughts on accessing $this->data['view_file'] the way I am?
    4. requnix, sorry for being the guy I am. Been trying for a decade xo
    5. Other comments welcome.



    PHP Code:
    <?php
    defined
    ('BASEPATH') OR exit('No direct script access allowed');

    class 
    Programs extends CI_Controller {

        public function 
    load($id=NULL)
            {
                
    $this->validate($id);
                
    $this->data['list_videos'] = $this->get_data($id);
                
    $this->load_views();
            }
        private function 
    validate($id=NULL)
            {
                
    $this->login_library->is_logged();
                if(
    $id==NULL)
                    {
                        
    $this->error();
                    }
                
    $query $this->db->get_where('pum_programs', array('id' => $id));
                if(
    $query->num_rows()==1)
                    {
                        return 
    true;
                    }
                else 
                    {
                        
    $this->error();
                    }        
            }
        protected function 
    get_data($id)
            {
                
    $query $this->db->get_where('pum_programs', array('id' => $id));
                
    $this->data['view_file'] = $query->result_array()[0]['view_file'];
                
    $query_videos $this->db->query("SELECT * FROM ".$query->result_array()[0]['content_database_table']." ORDER BY sort");
                return 
    $query_videos->result_array();
            }
        private function 
    load_views()
            {
                
    $this->load->view('header'$this->data);
                
    $this->load->view('nav'$this->data);
                
    $this->load->view($this->data['view_file'], $this->data);
                
    $this->load->view('footer'$this->data);
            }
        protected function 
    error()
            {
                echo 
    "Invalid Request";exit();
            }    
    }

    Thanks
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,265
    Rep Power
    9645
    Originally Posted by English Breakfast Tea
    Just pretending. I never knew and still don't know the difference between protected and private.
    protected means the class and its children can access it (protecting it from the outside world), private means only the class can access it (it's truly private to that class). There are two schools of thought here:
    1. Classes should be built so they can be extended easily. Given the choice, make something protected unless it should not be accessed by children directly.
    2. Classes should protect (heh) themselves against rogue children manipulating data. Given the choice, make something private unless it needs to be accessed by children directly.

    They're both equally valid.

    Originally Posted by English Breakfast Tea
    The way I deal with errors is gonna provoke some emotions I am sure.
    Yup, so I won't complain about that.

    Originally Posted by English Breakfast Tea
    Thoughts on accessing $this->data['view_file'] the way I am?
    I wouldn't think the view file itself needs to know that so I'd use a separate variable.


    Only other thing I would bitch about is
    PHP Code:
    defined('BASEPATH') OR exit('No direct script access allowed'); 
    that practice. I hate it. If the file shouldn't be accessed directly then it should not be able to be accessed directly: put it outside the web root. But I'm in a decent mood right now so... meh.
  4. #3
  5. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,156
    Rep Power
    220
    Thanks for the tips.

    Originally Posted by requinix
    Only other thing I would bitch about is
    PHP Code:
    defined('BASEPATH') OR exit('No direct script access allowed'); 
    that practice. I hate it. If the file shouldn't be accessed directly then it should not be able to be accessed directly: put it outside the web root. But I'm in a decent mood right now so... meh.
    That comes with Codeigniter's controller template they recommend it.

    I think they've given it to a bunch of high school students to make version 4
  6. #4
  7. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,265
    Rep Power
    9645
    Yeah, it makes the practice more excusable - you kinda have to do it that way - but I still hate it.

IMN logo majestic logo threadwatch logo seochat tools logo