OOP PHP Codeigniter Controller Hierarchy -


i'm having litle problems concepts of oop. i'll try explain best can.

i have class

class application_controller extends ci_controller{      public function additem(){         "some code add item database (working)";      } } 

and have class, both controllers:

require_once 'application_controller.php'; class contact extends application_controller{      public function __construct(){          parent::__construct("variables needed");      } } 

and in view add of contact added following action contact/additem.

ok, here's know oop in general.

isn't method additem supposed part of contact class because extends application_controller?

i'm asking because when submit form no action, , when add method additem in class contact overriding parent 1 works.

the reason no action codeigniter doesn't find method additem in contact class (update: due way codeigniter routing works). solution make additem generic method in model stores data in table, move model, , load model in controller.

create application/models/writemodel.php

class writemodel extends ci_model{   function additem(){     // code here   } } 

in controller:

    class contact extends controller{        function __controller(){           parent::controller();           $this->load->model('writemodel');        }         function somefunction(){           $this->writemodel->additem(); // call method here        }     } 

reference: codeigniter models


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -