全局无法识别超薄框架会话

时间:2017-10-01 20:42:29

标签: php session twig slim

我在index.php中有一个基本的苗条应用程序Caused by: org.apache.sling.models.factory.MissingElementsException: Could not inject all required fields into class com.aem.sites.models.HeaderList at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:593) at org.apache.sling.models.impl.ModelAdapterFactory.internalCreateModel(ModelAdapterFactory.java:335) at org.apache.sling.models.impl.ModelAdapterFactory.createModel(ModelAdapterFactory.java:223) at org.apache.sling.scripting.sightly.models.impl.SlingModelsUseProvider.provide(SlingModelsUseProvider.java:135) at org.apache.sling.scripting.sightly.impl.engine.extension.use.UseRuntimeExtension.call(UseRuntimeExtension.java:72) ... 209 common frames omitted Suppressed: org.apache.sling.models.factory.MissingElementException: Could not inject public org.apache.sling.api.resource.Resource com.aem.sites.models.HeaderList.headerList at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:598) ... 213 common frames omitted Caused by: org.apache.sling.models.factory.ModelClassException: No injector returned a non-null value! at org.apache.sling.models.impl.ModelAdapterFactory.injectElement(ModelAdapterFactory.java:513) at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:596)

我在一个名为Validator.php的类中给$ _SESSION一个值:

session_start()

在另一个类中,我将该变量全局设置为在twig模板中工作:

class Validator
{

    protected $errors;

    public function validate($request, array $rules)
    {
        // filled $errors with data

        $_SESSION['errors'] = $this->errors;
        var_dump($_SESSION); // doesn't work or show anything
        return $this;
    }

    public function failed() {
        return !empty($this->errors);
    }
}

最后,在我的Controller中调用会话变量:

class ValidationErrorsMiddleware extends Middleware
{

    protected $container;

    public function __invoke($request, $response, $next) {

        $twig = $this->container->view->getEnvironment();
        $twig->addGlobal('errors', $_SESSION['errors']);
        var_dump($_SESSION); // works
        $response = $next($request, $response);
        return $response;
    }
}

在我的Controller中,$ _SESSION变量始终为null,就好像它里面没有任何值一样。任何东西的var_dump都不起作用。但是在会话变量中显然存在IS值,因为当我在我的index.php中将其变为dumb时,会出现结果......我很困惑,我错过了什么?

0 个答案:

没有答案