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

  • SEARCH
  • Home
  • 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 8810305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:05:39+00:00 2026-06-14T03:05:39+00:00

I have been pouring over Zend_View and the various classes and interfaces that make

  • 0

I have been pouring over Zend_View and the various classes and interfaces that make up the view. One thing I am attempting to replicate in a project that does not use zend in any way shape or form is the:

$this->view->variable = 'Hello world';

that you can set in a controller and then do:

echo $this->view->variable;

My ultimate goal is to do something like:

$this->variable = new SomeClass

and then else where, in a view specifically, do:

$this->variable->someMethod();

My question is:

  • How would I replicate what zend does to do something simmilar with out using global variables?
  • How is zend able to do something like $this->view with out ever instantiating or saying what view is?

this would help me understand how, variables are passed around or objects are passed from the logic to the view and how php allows for something like $this->view to work when in a view or not.

note: this is not a Zend specific question and “use zend” is not the answer. I am looking to replicate a specific feature. My project does not in any way use or affiliate with zend.

  • 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-14T03:05:40+00:00Added an answer on June 14, 2026 at 3:05 am

    It’s actually pretty simple. When you use include, require, eval et al., the loaded code is brought in to the current scope. So if you have a template file

    template.php

    <span><?=$this->view->somevar?></span>
    

    Controller.php

    <?php
    class Controller
    {
        private $view;
    
        public function doSomething()
        {
            $this->view->somevar = 'Hello World';
            include 'template.php';
        }
    }
    

    index.php

    <?php
    require 'Controller.php';
    $oC = new Controller();
    $oC->doSomething();
    

    Blamo.., template.php is able to call $this->view->somevar as it is treated as part of Controller.php. Running php index.php on the CLI produces

    <span>Hello World</span>
    

    To elaborate a tiny bit, if $this->view inside of Controller.php were a class you’ve defined rather than a simple instance of stdClass as in the above demonstration, and it had a function someMethod, you could call $this->view->someMethod() from template.php just the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with SQL Server as a Developer a while. One thing
I have been pouring over the GWT Designer Quick Start documentation and for the
I have been pouring over the MYSQL documentation trying to determine if my script
Have been playing around with linq but there is one thing I cant seem
I have been pouring over many forums and questions similar (but not the same)
I have been pouring through documentation as part of my quarter long project to
Have been trying to encrypt an xml file to a string so that I
Have been reading about async and tasks and been attempting to convert the CopyFileEx
Have have been trying to make a validator for my xml files. I have
I have been developing line drawing apps that produce lines such as these: I

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.