Welcome Guest, Not a member yet? Register   Sign In
pre_render() event
#1

It would be great if there was a pre_render () event, so you could inject data into the view automatically. As for example, data referring to the session.
Reply
#2

(This post was last modified: 11-27-2017, 03:06 AM by PaulD.)

EDIT: Oops, sorry, did not realise this was for CI4, my answer is for CI3, my bad :-(

You can refer to session data directly in the view, so in a header for instance you can check if a session username is set and show it or show a log in button, for instance.

You can also fetch a view, with data sent to it like normal, and have the fully rendered HTML passed back as a string. Then you can 'inject' whatever you want, whatever 'inject' means.

PHP Code:
$html $this->load->view('home'$dataTRUE); // third option returns view as string. 

Is this what you meant by 'pre-render'?

Paul.
Reply
#3

That's an interesting suggestion. I have a feeling this might have been prompted by watching my failed attempt to do something similar in the repo for validation errors. Smile I was having a brain-fart at that moment, though, and simply using session('key') worked out pretty well, though might not so well in the parser.

I can also see this being very handy for other site-wide things you might want to make available, like things for the HTML meta tags, etc.

The biggest problem I can see is the event would be ran for every nested view, also, and quickly become a performance hit. I'll have to think on a good solution for this, but it's definitely a good idea.
Reply
#4

The events class should be handling this using event triggers in the view.

But this would need to be checked in the core class methods and for firing the triggers.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

I was doing an authentication system and I found that in each controller I have to pass user data, roles, etc. That's why I get the idea of an event that does it automatically in each render. Try to make the event, but run up to five times per render, it is not efficient.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB