2014-02-04 1 views
0

Почему контроллер шахты работает нормально при вызове напрямую, но не отвечает (хотя код действия, кажется, выполняется нормально) при вызове из другого контроллера? Ниже приведен пример кода.Почему мой ответ контроллера Kohana 3.3 NULL при вызове из другого контроллера?


// This contoller works ok when called directly 
// with a browser but its response is null when 
// it is called from within another controller 
// as it is meant to be (though the action 
// code seems to be executed ok in both cases) 
class Controller_Bar extends Controller_Template { 

    public $template = 'bar'; 

    public function action_index() 
    { 
     $items = ... // this gets populated with ORM 

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


// This contoller is meant to be called directly 
// with a browser and seems to work ok itself 
// but the controller it calls inside responds 
// with NULL in this case 
class Controller_Foo extends Controller_Template { 

    public $template = 'foo'; 

    public function action_index() 
    { 

     // I expected $barResponse to become a rendered 'bar' view 
     // which is meant to be a segment to be merged into the 
     // 'foo' view which becomes the resulting web page 
     $barResponse = Request::factory('bar')->execute()->response; 

     // but this writes NULL to the log 
     Log::instance()->add(Log::NOTICE, gettype($barResponse)); 

     $this->template->yoo = 'zzz'; // this works ok 

     $this->template->bar = $barResponse; 
    } 
} 

ответ

2

Request::execute() возвращает объект Response. Вы, вероятно, следовали устаревшему учебнику, $request->response - как он работал в предыдущей (3.1?) Второстепенной версии.

Это должно работать:

$response = Request::factory('bar')->execute(); 

$this->template->bar = $response->body();