1

I'm using twitter api to retrieve fav tweets, then parse them using a template:

$favs_list = $this->connection->get('favorites/list');
$data_to_parse['fav_list'] = $fav_list;
$html = $this->parser->parse('templates/tweet_list', $data_to_parse, TRUE);
$output['html'] = $html;
$this->load->view('read', $output);

the template tweet_list is simply:

<h3>Favs:</h3>
{fav_list}
<h5>{text}</h5>
{/fav_list}

But I keep getting these two error, and repeated multiple times:

A PHP Error was encountered    
Severity: 4096     
Message: Object of class stdClass could not be converted to string     
Filename: libraries/Parser.php
Line Number: 143

A PHP Error was encountered   
Severity: Notice     
Message: Object of class stdClass to string conversion     
Filename: libraries/Parser.php    
Line Number: 143

The weird thing is that, under these errors, my html is shown in correct format. Any idea on what caused this?

Community
  • 1
  • 1
iTurki
  • 16,292
  • 20
  • 87
  • 132
  • I think $favs_list is standard object array and you much get it converted to simple array and you are done. – TheMohanAhuja Feb 26 '14 at 05:48
  • @RakeshSharma $html id the basically my template `tweet_list` after parsing it. See: http://ellislab.com/codeigniter/user-guide/libraries/parser.html – iTurki Feb 26 '14 at 05:48
  • @TheMohanAhuja How to do that? – iTurki Feb 26 '14 at 05:49
  • I don't know optimal method but I do usually with json_encode(json_decode ($favs_list, true)); – TheMohanAhuja Feb 26 '14 at 05:52
  • @TheMohanAhuja I got an error saying: `json_decode() expects parameter 1 to be string, array given`. I'm guessing `$favs_list` is an array after all. – iTurki Feb 26 '14 at 05:55
  • 1
    sorry my mistake try this please json_decode(json_encode ($favs_list), true); – TheMohanAhuja Feb 26 '14 at 05:58
  • i dont know your structure of this stdClass Object, but you also can do thinks like this (array)$stdClassValue ... this will also do this encode / decode job from your json functions ;) – dschibait Feb 26 '14 at 06:33
  • @TheMohanAhuja This works perfectly. Although I chose to use [this way](http://stackoverflow.com/a/11577501/543711). Please post an answer so that I can accept it. – iTurki Feb 26 '14 at 07:51

2 Answers2

2

I don't know optimal method but I do usually with

json_decode(json_encode ($favs_list), true);
TheMohanAhuja
  • 1,855
  • 2
  • 19
  • 30
0

You are trying to print out favs_list but the content is an object, and its having a hard time trying to convert that object.

Just convert the object to an array instead and use accordingly

$array = (array) $object;

in your case

$favs_list = $this->connection->get('favorites/list');
$data_to_parse['fav_list'] = (array) $fav_list;
Raymond Ativie
  • 1,747
  • 2
  • 26
  • 50