Question

I am using CodeIgniter with PyroCMS in my work as a website developer. Some colleagues who have used Pyro much longer than I have are using the Pyro tags a lot. They seem extremely useful, even if I don't have a clue how they work yet. Anyway, I was trying to use the tags in a PHP array, but Pyro doesn't seem to like that.

The code in question:

{{ eods }}
    <tr>
        <td value="{{ user_id }}" class = "span1">{{ user_id }}</td>
        <td value="{{ eod }}" class = "span2">{{ eod }}</td>
        <td value="{{ mit_id }}" class = "span2"><?php echo $this->db->get_where('mit', array('id' => {{ mit_id }})); ?></td>
        <td value="{{ date }}" class = "span2">{{ date }}</td>
        <td value="{{ time }}" class = "span2">{{ time }}</td>
    </tr>
{{ /eods }}

I get the error:

Parse error: syntax error, unexpected '{' in C:\repos\mit-eod\addons\shared_addons\modules\mit\views\history.php on line 48

The error is on the line with the php code (line 5), in the PHP echo statement. I can confirm it's the third opening curly brace on the line, the first one in {{ mit_id }}.

Why is this happening?

Was it helpful?

Solution

You can't use tags in PHP code, as the PHP code will be interpreted as PHP code first, not part of the template. You should do the logic in your controller or model and pass whatever you're getting from the DB in the $eods variable to the template.

Also,

<?php echo $this->db->get_where('mit', array('id' => $thing)); ?>

will get a MySQL (probably) result, not a single value. You will at least need to do something like:

$var = $this->db->get_where('mit', array('id' => $thing))->row()->thing;

but that will throw an error if no rows are found. A MySQL join might be better.

Good luck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top