• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
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.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
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 the CodeIgniter Community in 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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.