there are two sample here,
1.
in controller
$result_article = $this->cms->get_content($event_id);
if($result_article->num_rows() == 1){
$data['row'] = $result_article->row();
}
in my view
<?php echo $row->title; ?>
print_r($row)/print_r($result_article->row()); output
stdClass Object ( [id] => 43 [title] => Grant visit by Prime Minister [content] => this is the content [create_date] => 2012-09-21 [last_update] => 2012-09-22 19:27:12 )
with error appeared
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: libraries/Parser.php
Line Number: 101
2.
in controller
$result_article = $this->cms->get_content($event_id);
if($result_article->num_rows() == 1){
$row = $result_article->row();
$data = array(
'title' => $row->title
);
}
in my view
<?php echo $title; ?>
print_r($title) output
Grant visit by Prime Minister
no error.
what is the different between the 1st controller and 2nd code, it suppose to be the same output right? i am confused!
to make it more clear, i have simplified the code
here is the model
function get_content($event_id){
$this->db->select('id,title,content,create_date,last_update');
$query = $this->db->get_where('events',array('id' => $event_id));
return $query;
}
the controller
$data['query'] = $this->cms->get_content($this->uri->segment(3));
if($data['query']->num_rows() == 1){
$row = $data['query']->row();
<!--with this code, no error appear-->
$data = array(
'title' => $row->title,
'content' => $row->content,
'create_date' => $row->create_date,
'last_update' => $row->last_update,
'event_id' => $row->id
);
<!--with this code, no error appear-->
if is only these code
$data['query'] = $this->cms->get_content($this->uri->segment(3));
if($data['query']->num_rows() == 1){
$row = $data['query']->row();
error happen,
A PHP Error was encountered
Severity: 4096
Message: Object of class CI_DB_mysql_result could not be converted to string
Filename: libraries/Parser.php
Line Number: 101
print_r($result_article->row());