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

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

    Is it proper? Loading helpers and doing things other than database actions in model?


    I was reading Codeigniter's document and I ran into this model.
    I am a bit surprised there are few things here that could be moved to controller. Would you change this model and put some of this in controller?
    PHP Code:
    public function set_news()
    {
        
    $this->load->helper('url');
        
        
    $slug url_title($this->input->post('title'), 'dash'TRUE);
        
        
    $data = array(
            
    'title' => $this->input->post('title'),
            
    'slug' => $slug,
            
    'text' => $this->input->post('text')
        );
        
        return 
    $this->db->insert('news'$data);

    Thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,989
    Rep Power
    375
    they probably did it to keep controller file SKINNY.. in general controllers should not do any processing.. Models should do all the work..
  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 paulh1983
    they probably did it to keep controller file SKINNY.. in general controllers should not do any processing.. Models should do all the work..
    Why not putting thoses processes in helper or library rather than model (which brings me to the next question, what is the difference between helpers and libraries)?
    Thanks
    Last edited by zxcvbnm; February 2nd, 2013 at 03:01 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,989
    Rep Power
    375
    libraries are like classes. helper is just any old file with bunch of function stuck together.

    this is what i understand anyway. Could be wrong

IMN logo majestic logo threadwatch logo seochat tools logo