0

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
2
  • Yes, please accept some answers. Then, give us the output of this: print_r($result_article->row()); Commented Sep 22, 2012 at 20:25
  • i have edited my ans and included the print_r output. Commented Sep 23, 2012 at 0:56

3 Answers 3

1

In your view in situation 1 it should be

<?php echo $article->row->title; ?>

to make the code the same as in situation 2.

As I see it, $article is a collection of rows, so you have to access a row from a article, and then get the title of that row.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to serialize() the 'row' before gettin the title. Because your query, I guess, returns a xml format (correct me if I'm wrong).

Comments

0

For those that have this issue, replace in \system\libraries\Parser.php:

$template = $this->_parse_single($key, (string)$val, $template);

To:

if (!is_object($val)) $template = $this->_parse_single($key, (string)$val, $template);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.