Welcome Guest, Not a member yet? Register   Sign In
Error require_once
#1

[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 */
#2

[eluser]Eric Barnes[/eluser]
I would probably say you should be using a library or a helper for this.
#3

[eluser]Alex-Tunbridge[/eluser]
Try this.

Instead of:
Code:
function Advertisement() {
      parent::Model();
  }

Do:
Code:
function Advertisement() {
      parent::Model();
      $this->load->model('add');
  }

and just get rid of your require all together.
#4

[eluser]iConTM[/eluser]
I tried $this->load->model() but this method generates only one instance Confused

Tx for the replies
#5

[eluser]Buso[/eluser]
Once the method is loaded you can use new if you need to create more instances
#6

[eluser]iConTM[/eluser]
can you give an example?
#7

[eluser]iConTM[/eluser]
aha found it:

<?php

$this->load->model('Some_model');

$instance = new $this->Some_model();

?>
#8

[eluser]Buso[/eluser]
Code:
$this->load->model('Some_model');

$instance1 = new Some_model();

$instance2 = new Some_model();




Theme © iAndrew 2016 - Forum software by © MyBB