Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Cannot access flashSession or getting 500 error

I am trying to output flashSession on my view.

I am setting shared flashSession like this

$flashData = [
    'error' => 'alert alert-danger',
    'success' => 'alert alert-success',
    'notice' => 'alert alert-info',
];

$flash = new \Phalcon\Flash\Session($flashData);
$di->setShared('flashSession', $flash);

but when I am trying to print this out in my view (I am using volt)

{{ flashSession.output() }}

which is then translated to

<?php echo $this->flashSession->output(); ?>

I am getting in logs that the flashSession in not defined. I have then decided that I can put into controller

$this->view->flashSession = $this->flashSession

but then I am getting 500 html error when trying to ouput and I am not getting any error. Doean anyone know what it can be?



4.0k

I have also tried to do in BaseController this

public function beforeExecuteRoute()
{    
    var_dump($this->flashSession->getMessages());
}

but also here I am getting 500 error. I am getting always 500 error when I am trying to output or get messages. When I am doing

$this->flashSession->error('some error');

or

$this->flashSession->message('error', 'some error');

And not doing output, then I am not getting 500 error.



22.3k
edited Jul '14

You should have something like this in your bootstrap file:

$di->set('flash', function() {
        $flash = new \Phalcon\Flash\Session([
            'error'   => 'alert alert-danger',
            'success' => 'alert alert-success',
            'notice'  => 'alert alert-info',
            'warning' => 'alert alert-warning',
        ]);
        return $flash;
    });

Or in your case maybe something like this:

$di->set('flashSession', function() {
        $flash = new \Phalcon\Flash\Session([
            'error'   => 'alert alert-danger',
            'success' => 'alert alert-success',
            'notice'  => 'alert alert-info',
            'warning' => 'alert alert-warning',
        ]);
        return $flash;
    });


4.0k

@Flanex This

$di->set('flashSession', function() {
    $flash = new \Phalcon\Flash\Session([
        'error'   => 'alert alert-danger',
        'success' => 'alert alert-success',
        'notice'  => 'alert alert-info',
        'warning' => 'alert alert-warning',
    ]);
    return $flash;
});

is exactly the same as this

$flashData = [
    'error' => 'alert alert-danger',
    'success' => 'alert alert-success',
    'notice' => 'alert alert-info',
];

$flash = new \Phalcon\Flash\Session($flashData);
$di->setShared('flashSession', $flash);

I have got just setShared instead of set, and ofcourse it is also not working.



4.0k

I think that this can be something with the configuration of PHP, because I am getting this:

[Fri Jul 04 00:49:44 2014] [error] [client xxxxxx] (104)Connection reset by peer: FastCGI: comm with server "/var/www/.../cgi-bin/php5-fcgi-*-80-domain.com" aborted: read failed
[Fri Jul 04 00:49:44 2014] [error] [client xxxxxx] FastCGI: incomplete headers (0 bytes) received from server "/var/www/.../cgi-bin/php5-fcgi-*-80-domain.com"
[Fri Jul 04 00:49:44 2014] [error] [client xxxxxx] client denied by server configuration: /var/www/domain.com/web/error/500.html

but dont have a clue what is wrong



4.0k
Accepted
answer

Ok, I have got this working after compiling from ext

cd ext
phpize
./configure CFLAGS="-O0 -g3" --with-php-config=/usr/bin/php-config
make -j16
make install