Welcome Guest, Not a member yet? Register   Sign In
Parse template/data
#1

[eluser]stuffradio[/eluser]
I want to know how to parse a template with the native template parser as well as add the normal Model data to the view.

Example:

Code:
$data['something'] = $this->model->function();
$data = array(
              'blah' => 'BLAH'
             );
$this->parser->parse('viewfile', $data);
Won't add the something, as far as I know.

So I want to do the same thing as
Code:
$this->load->view('viewfile', $data);
With the parser library.
#2

[eluser]Jondolar[/eluser]
Merge your original $data array with your second array instead of reassigning a new array to $data. use the array_merge() function.
#3

[eluser]stuffradio[/eluser]
Using my own parser library

Code:
<?php

class Parserlib
{

    function Parserlib()
    {
    $this->CI =& get_instance();
    }
    
    function replaceIt($pattern = array(), $string, $replace = array())
    {
        ksort($pattern);
        ksort($replace);

        return str_replace($pattern, $replace, $string);        
    }
    
}
#4

[eluser]Jondolar[/eluser]
Stuffradio, I don't think that was his problem. He has two arrays with find/replace pairs, not one array with find pattern and another array with replace pattern. He needs to either merge his arrays or he needs move the $data['something'] assignment below the line that creates the $data array in the first place.
#5

[eluser]stuffradio[/eluser]
Jondolar you just replied to my post as if I wasn't the OP.

I can't use the template parser the way I want to, I already know about the array merging issue but that wasn't going to solve it anyways.
#6

[eluser]Jondolar[/eluser]
LOL, sorry, I'm not on drugs, really.
#7

[eluser]stuffradio[/eluser]
[quote author="Jondolar" date="1247962319"]LOL, sorry, I'm not on drugs, really.[/quote]

That's what they all say Wink




Theme © iAndrew 2016 - Forum software by © MyBB