Welcome Guest, Not a member yet? Register   Sign In
How to setup controller for view ouput using the template parser.
#1

[eluser]brandonrichards[/eluser]
Hey folks

I'm using codeignitor on a personal project of mine and while learning to use it I've started implementing the template parser for my view output.

My question isn't so much a codeignitor problem that it is understanding how to deal with my model data in the controller and push it out to the output filter properly.

Here is the specific model function I have:

Code:
function request_all_with_tags()
{  
        $sql = "SELECT _request, GROUP_CONCAT(_tag_name) AS tags
                FROM pr
                INNER JOIN tr ON tr._rid = pr._id
                INNER JOIN tags ON tr._tid = t._tid
                GROUP BY _request";
        
        $query = $this->db->query($sql);
        return $query;
}
Here is my controller index():

Code:
function index()
{

$this->load->model('Request_Model');
$query = $this->Request_Model->request_all_with_tags();
$tagquery = $query->result('tags');
$tag = explode(",",$tagquery);
$data = array
    (
      'title'=> "My Title",
      'heading' => "My Heading",
      'query' => $query->result('_request'),
'tags' => $tag
    );
        
$this->parser->parse('p_view', $data);
    }
My problem is taking the string made by the sql statement group_concat(_tag_name) as tags

and exploding it and then inserting it into my data['query'] array to output in my view such as

Here is what I want to do in my view: multiple tags belong to each _request

Code:
<ol>
{query}
    <li>{_request}
    <fieldset>
<legend>Tagged for:</legend>
<ul><li>{tags}</li></ul>
    </fieldset>
    </li>
{/query}
</ol>




Theme © iAndrew 2016 - Forum software by © MyBB