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 5972443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:39:31+00:00 2026-05-22T20:39:31+00:00

I’m having an issue with preserving the value of a variable after an HMVC

  • 0

I’m having an issue with preserving the value of a variable after an HMVC sub-request in Kohana 3.1.3.1 and am wondering how best to approach/fix it. I thought that additional requests in Kohana were isolated from each other, but it doesn’t seem to be the case…

First of all, I’ve created a controller to extend the Controller_Template:

abstract class Controller_Website extends Controller_Template {
public  $page_info;
public  $allow_caching;

public function before()
{
    // ... more unrelated code here ...

    // Only do this if auto_render is TRUE (default)
    if ($this->auto_render === TRUE AND $this->request->is_initial())
    {
        // Set our Page_Info to the values we just loaded from the database
        $this->page_info        = clone $this->navs[$slug];
    }

    // ... more unrelated code here ...
}

public function after()
{
    // ... more unrelated code here ...

    // For internal requests, let's just get everything except for the template
    if (! $this->request->is_initial())
    {
        $this->response->body($this->template->main_view->render());
    }

    // Only if auto_render is still TRUE (Default)
    if ($this->auto_render === TRUE AND $this->request->is_initial())
    {
        // ... more unrelated code here ...
        // ... get stuff from the database to populate the template ...

        // now render the response body
        $this->response->body($this->template->render());
    }

    // ... more unrelated code here...
    // including setting headers to disable/enable caching
}

}

And here’s an example of what one of the controllers looks like:

class Controller_Events extends Controller_Website {
    public function action_filtered()
    {
        // ... do some stuff ...

        // and set some values 
        $this->page_info->page_title    = 'Set in Events controller';

        // and some more stuff including generating some output
    }
}

Now I want one of my other controllers to be able to pull the output from the events controller, without the template. Controller_Website (above) takes care of excluding the template from the output, but consider this:

class Controller_Search extends Controller_Website {
    public function action_index()
    {
        // ... do some stuff ...

        // now let's include the result from our events controller
        $this->template->main_view->events  = Request::factory()
                                                ->controller('events')
                                                ->action('filtered')
                                                ->execute();

        // and set some values 
        $this->page_info->page_title    = 'Set in Search controller';

        // and some more stuff including generating some output
    }
}

So when my template calls echo $this->page_info->page_title; (remember, my template is only being included in the search controller’s output and not the event controller’s output), I’m expecting it to return “Set in Search controller” but instead it returns “Set in Events Controller”

The problem is that this action_filtered() method is very long and I’ve set up a couple routes that use this method to output several event pages (like filtering events by year, month, venue, city, etc.) so it doesn’t make sense to duplicate this method in my search controller. Hence the need for an HMVC request. When the filtered action is called as a main/initial request, it makes sense to set values in $page_info but when it’s called as a sub-request, I need to preserve the values set in the search controller, or whatever the initial controller is.

Of course, I could create an if statement in the events controller to only update these values if it’s a main request, but that’s less than ideal, obviously. There must be a way to make this sub-request run isolated from the initial request?

What am I doing wrong, or what’s the best way to go about solving this?

Thanks in advance!

DM

  • 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-05-22T20:39:32+00:00Added an answer on May 22, 2026 at 8:39 pm

    I found the problem/solution!

    The problem is that in my Controller_Website I had this in my action_before():

    // Create a new DM_Nav object to hold our page info
    // Make this page info available to all views as well
    $this->page_info = new DM_Nav;
    View::bind_global('page_info', $this->page_info);
    

    The problem is the bind_global – which is actually working as it’s supposed to by letting you change the value of this variable after the fact… (A very neat feature indeed.)

    The workaround/solution was to force the template to use only the original page_info by detecting if it was an initial/main request. So at the very end of the action_before() method of Controller_Website where it says:

    // Only if auto_render is still TRUE (Default)
    if ($this->auto_render === TRUE AND $this->request->is_initial())
    {
    

    I added this line to the end of that if statement:

        $this->template->page_info  = $this->page_info;
    }
    

    This line is redundant on initial/main requests, but it means that any additional sub-requests can still have access to their own page_info values without affecting the values used in the template. It appears, then, that if you assign a property to a view and then attempt to bind_global() the same property with new values, it doesn’t overwrite it and uses the original values instead… (Which is why this solution works.) Interesting.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.