Welcome Guest, Not a member yet? Register   Sign In
opting out of extraction
#1

[eluser]jordanarseno[/eluser]
When data is passed from the controller to the view, it is automatically extracted from the array, into associated variables.

Is there any way to opt out of this functionality?

For those that have watched Jeffery Way's video tutorials, I work the same way he does; Application data, along with the actual title of the view to be loaded is first loaded into a template view. The template loads the header, the content, and then the footer.

I desire to work with the template engine using the parser library, but this has been made very difficult, because the second parameter in $this->parser->parse() is the data to be extracted in the view, but it's extracted by the time it gets to the template!

Does this make sense? Haha.

Example:

In my Controller I have the following code...

Code:
...
$data['entities'] = $this->entity_model->get_all_entities_admin();
$data['main_content'] = 'admin_view';
$this->load->view("includes/logged_in_template", $data);
...

This loads the logged_in_template View...which contains, among other things:

Code:
...
$this->load->view("includes/admin_header.php");
$this->parser->parse($main_content, $entities);
$this->load->view("includes/logged_in_footer.php");
...

Now in the actual admin_view.php View I want to say:
Code:
...
{entities}
   {live}
   {datetime}
{/entities}
...

Where {live} and {datetime} are database columns that the get_all_entities_admin() function returned in the Controller. I know these work, I had them going in a dumbed-down view earlier...without the header/content/footer template system.

The problem is in:
Code:
$this->parser->parse($main_content, $entities);

I'm getting:

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


Not sure how to actually get my $entities information into the admin_view.
I tried subbing in $data for the second parameter, but it does not recognize it as a variable.

THANKS!
#2

[eluser]Cristian Gilè[/eluser]
Hi thelctrclengnr,

change
Code:
$data['entities'] = $this->entity_model->get_all_entities_admin();
to
Code:
$data['parser']['entities'] = $this->entity_model->get_all_entities_admin();

Update your logged_in_template view to:
Code:
...
$this->load->view("includes/admin_header.php");
$this->parser->parse($main_content, $parser);
$this->load->view("includes/logged_in_footer.php");

Now, in your admin_view view you can iterate entities.

Cristian Gilè
#3

[eluser]jordanarseno[/eluser]
you sir,

are a genius +1 !!

thank you very much - flawless!
#4

[eluser]jordanarseno[/eluser]
Oops! spoke too soon Smile

It appears that the parse() function causes the view to render before my header, even though it is between the header and footer.

Any ideas?

Thanks again!
#5

[eluser]Cristian Gilè[/eluser]
Very strange. The parser output should be appended to the final output.

Try this:

Code:
$parser_content = $this->parser->parse($main_content, $entities, TRUE);
$this->load->view("includes/admin_header.php");
echo $parser_content;
$this->load->view("includes/logged_in_footer.php");

Cristian Gilè
#6

[eluser]jordanarseno[/eluser]
Strange, but it works...Provided I pass an array of objects.
Time to go into all my models and ensure arrays of objects are returned, even if it's redundant!

Thanks again Cristian!

Cheers!
#7

[eluser]Unknown[/eluser]
Hi Cristian Gilè,

I dont know how u found the answer. it sure works. thank u.




Theme © iAndrew 2016 - Forum software by © MyBB