getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
634 stars 95 forks source link

Session not working #159

Closed giwrgos88 closed 7 years ago

giwrgos88 commented 7 years ago

I'm using the session_flashed to get the input fields in case of an error but it returns back a null value. I have tested that I'm returning back an array of the inputs,which works, but on the view is null. same with my validation messages.

Also is good to mention that I'm loading the view using this method herbert('Twig_Environment')->addExtension(new Test\WordpressTemplate\WordpressTemplateExtension());

namespace Test\WordpressTemplate;

class WordpressTemplateExtension extends \Twig_Extension
{

    public function getFunctions()
    {
        return array(
            'header' => new \Twig_Function_Method($this, 'header'),
            'footer' => new \Twig_Function_Method($this, 'footer'),
            'sidebar' => new \Twig_Function_Method($this, 'sidebar')
        );
    }

    public function header($string = null)
    {   
        return get_header( $string );
    }

    public function footer($string = null)
    {
        return get_footer( $string );
    }

    public function sidebar($string = null)
    {
        return dynamic_sidebar( $string );
    }

    public function getName()
    {
        return 'template';
    }
}

Does anyone knows what is wrong?

giwrgos88 commented 7 years ago

Ok I found a solution. So I added a function into "WordpressTemplateExtension"

public function getGlobals() {
        return array(
            'session' => $_SESSION,
        );
    }

An in my controller I did the following

session()->set('__form_data', $inputs);
session()->set('error', $validator->messages());