How to save variable value after HMVC subquery in Kohana 3.1?

I had a problem saving the value of a variable after the HMVC subquery in Kohana 3.1.3.1, and I am wondering what is the best way to approach / fix it. I thought that the additional requests in Cohan were isolated from each other, but it seems that this is not so ...

First of all, I created a controller for the Controller_Template extension:

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 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 is 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 output the output from the event controller without a template. Controller_Website (see above) takes care of excluding the template from the output, but think about it:

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

        // now let 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
    }
}

, echo $this->page_info->page_title; (, , ), , " ", " "

, action_filtered() , , (, , , , ..), . HMVC. / , $page_info, , , , .

, if , , , . ?

, ?

!

DM

+3
2

/!

, _Website 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);

, bind_global - , , ... ( .)

/ , page_info, , / . , action_before() Controller_Website, :

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

if:

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

/ , , - page_info, , . , bind_global() , ... ( .) .

0
Request::factory()
    ->controller('events')
    ->action('filtered')
    ->execute();

. Request::factory() Request ( URI). HMVC URI:

Request::factory(Request::current()->uri(array(
    'controller' => 'events', 
    'action' => 'filtered'
)))->execute();

PS. , . 3.1. , Request- > uri().

0

All Articles