Welcome Guest, Not a member yet? Register   Sign In
single ds with MVC?
#1

[eluser]Matthew90[/eluser]
Hello,

today I have started to work with CI and my first impression is really good :-)
As this is my first job with a framework, the MVC-Model and strict OOP-Programming is new for me.
Now I have an problem with the MVC-Model.
It concerns the following...
I want to return a single data set... without oop no problem:
Code:
$this->db->where(array('id' => $this->uri->segment(3)));
        $query = $this->db->get('projects');
        
        
        if ($query->num_rows() > 0) {
            $row = $query->row();
        
               echo $row->id;
               echo $row->description;
                    
           //...
        }
But how can I do it, when I want to work with the model class?
I tried a lot of iddeas but without a result...
At the moment my code is as followed:

project_model.php
Code:
function get_requested_project($where)
    {
        $this->db->where($where);
        $query = $this->db->get('projects');
        
        if ($query->num_rows() > 0) {
            return $query->row();
        }
        else {
            return false;
        }
    }

admin.php
Code:
function insert_project()
    {
        $this->load->model('project_model');
        
        $row=$this->project_model->get_project(array('id' => $this->uri->segment(3)));
        if ($row != false) {
               echo $row->id;
               echo $row->description;
                    
            $this->load->view('project_insert',$data);
        }

I hope you know what I mean in spite of my bad English and I look forward to get an answer ;-)

Greetings

Matthew
#2

[eluser]Matthew90[/eluser]
Does nobody have an idea?
#3

[eluser]obiron2[/eluser]
if you replace

Code:
return $query->row();

with
Code:
return $query->result();

You will get an object back which is an array of objects, each one being a row of data.

if you have returned the object to $resultSet you can then manipulate it by using the array offset and the row field names

Code:
print $resultSet[3]->fieldname;

or
Code:
foreach ($resultSet as $resultRow)
{
  print $resultRow->fieldname1 . "<BR>" $resultRow->fieldname2;

}

you can even take each resultRow and convert that to a Key->Value array

Code:
foreach ($resultRow as $resultKey => $resultValue)
{
  print $resultKey . ":" . $resultValue . "<BR>";
}
#4

[eluser]Matthew90[/eluser]
thx for your help obiron2, now it works fine :lol:




Theme © iAndrew 2016 - Forum software by © MyBB