【发布时间】:2018-06-22 03:29:58
【问题描述】:
首先,对不起我的英语,其次是我的错误
注意:试图获取非对象的属性 C:\wamp64\www\projeto\app\OfertasVendor\Middleware\ValidationErrorsMiddleware.php 在第 9 行
ValidationErrorsMiddleware.php的第9行是:
$this->container->view->getEnvironment()->addGlobal('errors',$_SESSION['errors']);
ValidationErrorsMiddleware.php的完整代码是
<?php
namespace OfertasVendor\Middleware;
class ValidationErrorsMiddleware extends Middleware{
public function __invoke($req, $res, $next){ $this->container->view->getEnvironment()->addGlobal('errors',$_SESSION['errors']);
//var_dump($_SESSION['errors']);
//unset($_SESSION['errors']);
var_dump('teste');
$res = $next($req, $res);
return $res;
}
}
但是,我已经制作了 Middleware.php,我通过了容器, 中间件代码:
namespace OfertasVendor\Middleware;
//use OfertasVendor\Controllers\DatabaseController;
class Middleware{
protected $container;
public function __contruct($container){
$this->container = $container;
}
}
我只需要传递容器->视图,但是,框架无法识别容器...
我已经制作了Controller.php
namespace OfertasVendor\Controllers;
abstract class Controller{
protected $container;
public function __construct($container){
$this->container = $container;
}
public function __get($key){
if($this->container->{$key}){
return $this->container->{$key};
}
}
}
我的应用 index.php 有中间件
$app->add(new \OfertasVendor\Middleware\ValidationErrorsMiddleware($container));
你能帮帮我吗?
【问题讨论】:
-
第 9 行 哪一行是第 9 行。从您在这里粘贴的代码中看不清楚
-
第9行是$this->container->view->getEnvironment()->addGlobal('errors',$_SESSION['errors']);
-
嗯,你认为是对象的事情之一不是对象
-
他们说“视图”不是一个对象,但我需要这个对象......我在其余代码中使用视图对象并且工作,但在这个文件中不起作用
标签: php frameworks slim