i want to use different objects inside the template. different objects are created on different section of the site.
currently my code is
public function notify ($template, $info)
{
ob_start();
include $template;
$content = ob_get_clean();
//... more further code
}
as you see $info parameter. i dont want to use $info inside templates, but i was to use $photo, $admin or whatever is passed to it.
which i use like
// for feed
$user->notify('email_template_feed.php', $feed);
// for new photo - i would also like to use $user inside templates
$user->notify('email_template_photo.php', $photo);
how can i do that? cant use global, because is inside function and function is getting called dynamically on different locations/sections of the site, which can further extend.
You can’t.
Solution 1
Instead you could use an array and extract its values:
Example 1
if you call it with:
and inside the template
email_template_feed.php:it will print:
Solution 2
You could also pass the name of the variable as third parameter:
Example 2
You could then call it via: