Welcome Guest, Not a member yet? Register   Sign In
Parser Library Problem
#1

[eluser]egunay[/eluser]
Hello,

Today I found out the parser library. I was trying to test it as it is written on the documentation (I'm trying to say that I didn't change anything?)

But I got an error as:

______________________________________________________________________________
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: 63
_______________________________________________________________________________

Can someone please tell me what did I do wrong?
#2

[eluser]pickupman[/eluser]
You didn't post any of your code, so it's hard to tell you what went wrong. I would guess you are not retrieving the result object properly. (ie $row = $query->row() );
#3

[eluser]egunay[/eluser]
Sorry about that, I was thinking maybe it was a common problem or sth.

Here it is;

Controller:
Code:
<?php
class Lmp extends MY_Controller {

    function index()
    {
        $data['title'] = "Title";
        $data['posts'] = $this->db->query("SELECT title, body FROM posts");

        $this->parser->parse("theme1/lmp_view", $data);

    }    
}
?>



View:
Code:
<?php
    
     $post1 = $posts->result_array();
     echo $post1['title'];
    
?>
#4

[eluser]egunay[/eluser]
I've changed my view to this;

View:
Code:
<?php
    foreach ($posts->result_array() as $row)
    {
       echo $row['title'];
       echo $row['body'];
    }
    ?>

And now I can at least see the post titles etc. but I'm still getting

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: 63

Error on the top of the page.
#5

[eluser]egunay[/eluser]
Woww!

I think I've fixed the problem somehow?!

I'm pasting it here so that maybe someone else having the same problem can see it:

I have changed my controller to:
Code:
<?php
class Lmp extends MY_Controller {

    function index()
    {
        $data['site_title'] = "Title";
        $entries = $this->db->query("SELECT title, body FROM posts");
        $data['posts'] = $entries->result_array();
        $this->parser->parse("theme1/lmp_view", $data);

    }    
}
?>


And my view to:
Code:
<some html......>
{posts}
{title}
{/posts}
<some other html>....

In my case parser library is loaded automatically from autoload.php file. If you don't specify it ofcourse you have to load it in your controller.

Thanks anyway @pickupman for your attention.
#6

[eluser]pickupman[/eluser]
When you use the parser library, you don't reference the variables, you would use {variable} instead. Glad you got it worked out.




Theme © iAndrew 2016 - Forum software by © MyBB