Error require_once - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Error require_once (/showthread.php?tid=30961) |
Error require_once - El Forum - 06-01-2010 [eluser]iConTM[/eluser] Hi, I want to require a class for the model below. The goal of this class is to store translated data from the database before it is passed to the view. (e.g. htmlspecialchars ect.) Is this a good practice? <?php require_once APPPATH . 'models/add.php'; class Advertisement extends Model { function Advertisement() { parent::Model(); } function get () { $query = $this->db->query("SELECT * FROM advertising ORDER BY name ASC;"); $adds = array(); foreach ($query->result() as $row) { $add = new Add(); $add->id = $row->id; $add->name = htmlspecialchars($row->name); $add->link = $row->link; $add->image = $row->image; $add->hits = $row->hits; $add->firstdate = $row->firstdate; $add->imagepresent = $row->imagepresent; $add->listed = $row->listed; $add->impressions = $row->impressions; $adds[] = $add; } return $adds; } } /* End of file advertisement.php */ /* Location: ./system/application/models/advertisement.php */ Error require_once - El Forum - 06-01-2010 [eluser]Eric Barnes[/eluser] I would probably say you should be using a library or a helper for this. Error require_once - El Forum - 06-01-2010 [eluser]Alex-Tunbridge[/eluser] Try this. Instead of: Code: function Advertisement() { Do: Code: function Advertisement() { and just get rid of your require all together. Error require_once - El Forum - 06-02-2010 [eluser]iConTM[/eluser] I tried $this->load->model() but this method generates only one instance Tx for the replies Error require_once - El Forum - 06-02-2010 [eluser]Buso[/eluser] Once the method is loaded you can use new if you need to create more instances Error require_once - El Forum - 06-02-2010 [eluser]iConTM[/eluser] can you give an example? Error require_once - El Forum - 06-02-2010 [eluser]iConTM[/eluser] aha found it: <?php $this->load->model('Some_model'); $instance = new $this->Some_model(); ?> Error require_once - El Forum - 06-02-2010 [eluser]Buso[/eluser] Code: $this->load->model('Some_model'); |