I am new to phalcon framework. I have set the variable email in my TblUserController's edit action as
$tbl_user = TblUser::findFirstByuser_id($user_id);
$this->view->setVar("email", $tbl_user->email);
and in tbl_user/edit.volt I write like:
{{ tbl_user.email }}
but it gives error
Undefined variable: tbl_user
I'm not familiar with Phalcon but I think you need to do:
$this->view->setVar("email", $tbl_user->email);
And use:
{{ email }}
Or
$this->view->setVar("tbl_user", $tbl_user);
And use:
{{ tbl_user.email }}
Related
As for Symfony4 translation, thanks to this article. It works well in Controller.
public function index(TranslatorInterface $translator)
{
$translated = $translator->trans('test');// it works
print $translated;exit;
in messages.en.yaml
test: englishtest
However I can't translate message in twig.
<br>
{{ test|trans }}
<br>
It shows the error Variable "test" does not exist.
I need to do something in advance for translation in twig???
The method signature looks like this:
{{ message|trans(arguments = [], domain = null, locale = null) }}
See https://symfony.com/doc/current/reference/twig_reference.html#trans
So if test is not a variable, then {{ 'test'|trans }} should work (as zalex already pointed out).
How can I get the value 'name' under 'rekenplichtige' in my Blade template? If I do this: {{ $vestiging->rekenplichtige->name }} I get the following error: ErrorException Trying to get property of non-object
That syntax is working to get the 'naam' under 'gemeente'. I have no idea about what's going wrong.
{{ $vestiging->rekenplichtige}}
since "name" inside an array, you should array notation to get name. Like below
{{ $vestiging->rekenplichtige['name'] }}
{{ $vestiging->rekenplichtige()->first()->name }}
This is working.
In their new documentation there isn't anything for flash messages.
I installed the flash extension from their github repository (slimphp/Slim-Flash). Everything works fine, I can add messages and can also get these messages.
// Adding a message
$this->flash->addMessage('test', 'This is a message');
// Getting a message
$this->flash->getMessage('test')[0];
But this only works inside routes. Of course I want to have these messages displayed on my view.
But I just don't know how to get this message on the twig view.
I have already tried:
{{ container.flash.message('test')[0] }}
{{ container.flash.getMessage('test')[0] }}
{{ this.flash.message('test')[0] }}
{{ this.flash.getMessage('test')[0] }}
{{ flash.message('test')[0] }}
{{ flash.getMessage('test')[0] }}
{{ app.flash.message('test')[0] }}
{{ app.flash.getMessage('test')[0] }}
{{ container.flash.test }}
Thanks for help!
You can add the flash message inside the data attribute from the render method:
$this->view->render($res, 'path/to/template.twig', [
'flash' => $this->flash
]);
Or you could add a middleware and add your flash instance to the twig parameters
$app->add(function ($request, $response, $next) {
$this->view->offsetSet("flash", $this->flash);
return $next($request, $response);
});
then it should be possible to access the messages inside the twig template with
{{ flash.getMessage('test') }}
I have a specific problem with concat of twig.
When I trying to concatenate dynamic variables showing the error.
Here is my code :
{% set i = 0 %}
{% set nbLignes = codeEvt.nb_lignes_~i %}
{% set nbLignesRef = codeEvt.nb_lignes_ref_~i %}
But I have this error message :
Method "nb_lignes_" for object "\DTO\SuiviJourFonc" does not exist in XXXXXXXXX.html.twig at line 211
I would like to take codeEvt.nb_lignes_0 , but i would like build a "for" for others variables like nb_lignes_1, nb_lignes_2 , nb_lignes_3 ...
How can i do this ?
attribute can be used to access a dynamic attribute of a variable:
The attribute function was added in Twig 1.2.
{{ attribute(object, method) }}
{{ attribute(object, method,arguments) }}
{{ attribute(array, item) }}
Try like this,
{{ attribute(codeEvt, 'nb_lignes_ref_' ~ i) }}
You can try the array-like notation:
{{ codeEvt['nb_lignes_ref_' ~ i] }}
Or even use string interpolation:
{{ codeEvt["nb_lignes_ref_#{i}"] }}
I'm sure there is a simple solution, but I am having trouble with an error for "illegal string offset" when processing form input for use with the Laravel Mail::send().
This is the code which processes the form input, as it has to be an array.
$msg = array(
'name'=>Input::get('name'),
'email'=>Input::get('email'),
'message'=>Input::get('message')
);
Then I try to send it through Mail::send().
Mail::send('emails.question', $msg, function($message) {
$message->to('myPersonalEmail#domain.com')->subject('Email from your website!');
});
The app/views/emails/question.blade.php template is extremely simple.
{{ $msg['name'] }} <br/>
{{ $msg['email'] }} <br/>
{{ $msg['message'] }}
Yet I still get the following error.
ErrorException (E_UNKNOWN)
Illegal string offset 'name' (View:
[intentionally omitted for privacy]/app/views/emails/question.blade.php)
I believe the error is referring to the $msg['name'] not being present, but if I return the view instead I do not receive an error at all.
return View::make('emails.questions')->with('msg',$msg);
What am I missing?
You have passed $msg as an associative array, so the items of $msg array are available to the view by $key. That's mean in your case like $name, $email and so on. The app/views/emails/question.blade.php now will be like this
{{ $name }} <br/>
{{ $email }} <br/>
{{ $message }}