pug-php / pug-symfony

Pug (Jade) template engine for Symfony

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined ofset when using csrf_token

coneforapine opened this issue · comments

Hi,
I was following guide from symfony's website to create a login form.

Everthing works fine with twig, but when I try to write login template with pug it just gives me undefined offset.

I'm actually newbie to pug and php so I may write it wrong

extends ../../base.pug

block content
   .container.login-container
       .col-8.login-form
           form(method="post")
               .form-group
                   input(type="text", name="user").form-control
                   input(type="password" name="password")
               .form-group
                   input(type="hidden" name="_csrf_token" value=csrf_token('authenticate'))
               .form-group
               button(type="submit")

image

When I remove csrf_token('authenticate') it renders fine but due to not having value in csrf I could not log in. Again I must say, it maybe me write it wrong but I don't know how to fix it either if its me.

commented

Hi, solution found, I will publish a patch to fix this soon.

@kylekatarnls will it fix #33 too? Just curious...

commented

Not sure because of the ... containing the real error. In fact Pug has a general debugger that catch the errors happening in the compiled PHP code, then tries to tell you what file/line/offset match it in the Pug source file. But this not works through the Symfony template layer, and the Undefined offset is an error of this debugger calculating the position hiding another real error.

So first now I allowed to get error messages (even if file/line is wrong) so you can now what is the real error. I should help you to guess what code chunk of your pug file could produce the error and so you could update your post #33 with this error message and code chunk.

About this issue #32, the real error is a bad calling of renderCsrf, so it's a problem specific to csrf_token.

Sure I will update #33 when I get back home

After resolving of #33 I can confirm its bad calling of renderCsrf...
Here the error message...

ErrorException in /mnt/c/Users/conef/Desktop/jobs/yuzbek/templates/main/component/base.pug:
Non-static method Symfony\Component\Form\FormRenderer::renderCsrfToken() should not be called statically on line 25, offset 1
commented

Fixed in pug-php/pug-symfony 2.6.2 You can update and retry.