Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:07:01+00:00 2026-06-17T14:07:01+00:00

i want to use different objects inside the template. different objects are created on

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:07:03+00:00Added an answer on June 17, 2026 at 2:07 pm

    You can’t.

    Solution 1

    Instead you could use an array and extract its values:

    public function notify ($__template, array $info)
    {
        ob_start();
        extract($info);
        include $__template; 
        $content = ob_get_clean();
        //... more further code
    }
    

    Example 1

    if you call it with:

    $user->notify('email_template_feed.php', array('feed' => $feed));
    

    and inside the template email_template_feed.php:

    ...
    <?=$feed?>
    ...
    

    it will print:

    ...
    FEED
    ...
    

    Solution 2

    You could also pass the name of the variable as third parameter:

    public function notify ($template, $info, $name)
    {
        ob_start();
        $$name = $info;
        unset($info);
        include $template; 
        $content = ob_get_clean();
        //... more further code
    }
    

    Example 2

    You could then call it via:

    $user->notify('email_template_feed.php', $feed, 'feed');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use variable in different function, I want to set global
I want to use two different Spring web contexts , each have own contextConfig,
Scenario I have a windows forms application. I want to use two different WCF
Does anyone know how to use different provider for membership? Actually i want to
I want to use multiple private keys to connect to different servers or different
I want to use type-safe variadic functions introduced in C++11, but not with different
I have some folder with different files. I want to use something like this:
I got a question ;) Actually I want to use core-data in different threads.
I want use this 1 for using Bar code or QR code scanner. I
I have some c# code running on sharepoint that i use to check inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.