fork(1) download
  1. <?php
  2.  
  3. //базовый класс контроллера
  4. class AppController{
  5.  
  6. protected $request ;
  7. protected $response;
  8. protected $args;
  9. protected $container;
  10.  
  11. public function __construct($request, $response, $container ,$args = null){
  12. $this->request = $request;
  13. $this->response = $response;
  14. $this->args = $args;
  15. $this->container = $container;
  16.  
  17. }
  18.  
  19. }
  20.  
  21. //класс контроллера
  22. class TestController extends AppController {
  23.  
  24.  
  25. public function __construct($request, $response, $container ,$args = null){
  26.  
  27. parent::__construct($request, $response, $container ,$args);
  28.  
  29. }
  30.  
  31. public function testRedirect(){
  32. //проблема в том что у меня отлично работает к примеру
  33. //все отрисовывается как нужно
  34. $this->container->view->render( $this->response, 'test.php', $data );
  35. // но не работает редирект
  36. $this->response->withRedirect('/', 301);
  37.  
  38. // в классе TestController объект $response доступен как $this->response и он доступен,
  39. // через var_dump печатается, но метод withRedirect не работает
  40.  
  41. }
  42.  
  43. }
  44.  
  45. $app->get('/test',function($request, $response){
  46.  
  47. //так я вызываю нужный контроллер и его метод
  48. //this в данном контексте - это контейнер который опеределяется в самом $app - слим
  49.  
  50. (new Controllers\TestController($request, $response, $this))->testRedirect();
  51.  
  52. });
  53.  
  54.  
  55.  
Runtime error #stdin #stdout #stderr 0.02s 24612KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Undefined variable: app in /home/cLeAe1/prog.php on line 45
PHP Fatal error:  Uncaught Error: Call to a member function get() on null in /home/cLeAe1/prog.php:45
Stack trace:
#0 {main}
  thrown in /home/cLeAe1/prog.php on line 45