[eluser]n0xie[/eluser]
If I understand correctly:
You have a model New
You have a model New
s
You have a simple controller
You want to pass whatever value comes from New to News, to get the associated information.
Based on these assumption this is how I would implement it in pseudocode:
Code:
// model new
class New_model extends Model {
private $id;
function New()
{
parent::Model();
}
public function getNew() { return $this->id; }
// you will probably make setNew private, but for this example let's just make it public
// so we can set it directly from the controller.
public function setNew($id) { $this->id = $id }
}
//model news
class News extends Model {
function News()
{
parent::Model();
}
// This would be getLastNews()
// Since we are already in the scope of news, getLast() should be sufficient.
public function getLast($id, $order='DESC', $limit='10')
{
$this->db->where('id',$id);
$this->db->order_by('Date', $order);
$this->db->limit($limit);
$query = $this->db->get('sometablename');
// just basic check if we get some results;
if ($query->num_rows() > 0)
{
return $query->result(); // returns the resultset as an object
return $query->result_array(); // returns the resultset as an array
}
else
{
// no results found, you can do w/e you want to handle this
// usually you just return FALSE and deal with it in the Controller where
// your business logic is.
return FALSE;
}
}
}
// controller
class Example extends Controller {
function Example()
{
parent::Controller();
}
function index()
{
$this->load->model('new');
$this->load->model('news');
// set some value
$this->new->setNew('1');
// retrieve some value
$id = $this->new->getNew();
// pass the value to another model
$data = $this->news->getLast($id);
// let's see what we got
var_dump($data);
}
}
Hope this helps. A small note: the CI coding style advices against using camelcase:
userguide