I have an application with Frontend(sales) and Backend(administration), what I want to do is to set the flash messages separated by context, because When I'm login in both context I'm received in the Backend messages that belong to the Frontend, and I don't want it.
Sorry about my English but I'm not an English speaker.
King Regards
If you are using the sessions flash bag then you just need to use different names when adding a message. For example you could use the following for admin messages:
// in your controller
$this->get('session')->getFlashBag()
->add('admin_error','No user found with that email address');
.........................................................
{# in your template #}
{% for flashMessage in app.session.flashbag.get('admin_error') %}
<div class="error-message">{{ flashMessage }}</div>
{% endfor %}
Then do the same thing in your public controllers/templates but replace 'admin_error' with something like 'public_error'.
Related
I am using FOSUserBundle with Symfony 3.4
I am trying to reset the user password and this works fine; only problem is that I can put ANY email and the status would be true saying that the email has been sent ??
How is it possible that FOS is finding a user that does not exist ? or did I miss something in my template ?
As far as I understand the status block is what should be displaying the error but it is always a success.
I have not overridden any of the default controller
{% extends 'UserBundle:Resetting:request.html.twig' %}
{% trans_default_domain 'FOSUserBundle' %}
{% block status %}
{{ 'resetting.check_email'|trans({'%tokenLifetime%': tokenLifetime})|nl2br }}
{% endblock %}
I think there is no problem and in addition it is a good behavior. Because otherwise, a person could easily devour a lot of users, which will cause a security problem. So if the user does not exist, not the pain to mention.
Again, if you look closely at this class (in fosuserbundle repository) via the link :
ResettingController, more precisely the method sendEmailAction, at the level of the 2nd control structure if
if (null !== $user && !$user->isPasswordRequestNonExpired($this->retryTtl))
you can notice that if the user does not exist then no mail is sent, the instructions inside the if are not executed and we go directly to a redirection instruction.
return new RedirectResponse($this->generateUrl('fos_user_resetting_check_email', array('username' => $username)));
That's why you see success all the time. Also this redirection above can be executed even in the case the user exists. That's how I tried to have an attempt to understand this process.
Is there a way to check if a current page belongs to a collection? If so, can I check what’s the label of the collection?
Background story:
What I’m trying to achieve is to display a different layout for all pages that belong to a collection. With this new layout I want to display a side navigation (some sort of „See also”) with listing of all pages in the collection that the current site belongs to.
In case my question turns out to be dumb – forgive me, I’m new to jekyll and I really tried to find out the answer by myself.
page.collection returns the label of the collection to which the document belongs. So I guess you want to do something like:
{% if page.collection == 'COLLECTION_LABEL' %}
NEW LAYOUT
{% else %}
OLD LAYOUT
{% endif %}
To access the pages in a collection, you can use the label with site.COLLECTION_LABEL or site[COLLECTION_LABEL] (you need [] if it is a variable). Something like:
{% for page in site[page.collection] %}
{{ page.title }}
{% endfor %}
Any collection document has a page.collection variable which is the collection label.
But, if you want to associate a specific layout to a collection, you can use default configuration :
defaults:
-
scope:
type: mycollection
values:
layout: a_custom_layout
anyvar: a_custom_var
I'm a new in OroCRM and Symfony2. I'm trying to code a page that retrieves all record of a table. But I don't know how to change title of this page, it always displays it's url (http://localhost/crm-application/web/app_dev.php/...).
This is my twig file:
{#index.html.twig#}
{% extends 'OroUIBundle:actions:index.html.twig' %}
{% import 'OroUIBundle::macros.html.twig' as UI %}
{% set gridName = 'b2b-customers-grid' %}
{% set pageTitle = 'B2B Customers' %}
I have tried many way but i could not make it. I usually get that error:
A template that extends another one cannot have a body”
Any help? Thanks a lot. :)
pageTitle is not that title that you think of, as I understand you want to set title for the whole page, browser window title, head > title in html, and pageTitle variable it's for content header title.
Do you have any other content in your index.html.twig? That could be the reason you got an error.
To set window title, you should use navigation.yml in your bundle's Resources/config with something like
oro_titles:
orocrm_account_index: ~
or
oro_titles:
orocrm_account_index: 'Create Account'
Don't forget to clear cache after that, if you had no this file before and run app/console oro:navigation:init to reload titles configuration
About the messaging framework, in the docs it is written that every message has a message.tag property that can be uses for css. so my code looks like this
try:
models.save()
message.success(request, "Model successfully saved")
except DatabaseManagementTransaction:
message.error(request, "Model could not be saved")
in my html template
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{message.tag}} alert-dissmissable">
{{message}}
</div>
{%endfor%}
{% endif %}
But when the template is rendered i see no message.tag and the div class looks like this
<div class="alert alert- alert-dissmissable">...</div>
So do i have to create MESSAGE_TAGS in settings file for this to work? Why is the message.tag empty? And another question. What happens to messages after they are presented to user? Are they deleted? If i add a new model will the previous messages be shown to me plus the newly appended one?
If should be tags as alert-{{message.tags}} in the template.
What happens to messages after they are presented to user? Are they deleted?
Yes, they are cleared once iterated (or displayed through template) from the storage. Refer message expiry.
If i add a new model will the previous messages be shown to me plus the newly appended one?
The messages list will have all currently active messages. So if previous message is still there it will be shown as well.
I want to check if a form is new in my template, something like $form->isNew() in symfony 1.4, but i did not find a solution.
Currently, i'm using this technique:
{% null != entity.getId %}
it works, but are there other solutions which are more clean?
I use this:
{% if form.vars.submitted == false %}DO WHATEVER HERE{% endif %}
More info in form functions and variables here:
https://symfony.com/doc/current/reference/forms/twig_reference.html
Symfony2 forms are less coupled to the model than symfony1 forms. Form in Symfony2 cannot be "new" or "old". It's the entity which is persisted, not the form. Forms job is to put submitted data to the model object.
Remember that model class doesn't have to be a doctrine entity (can be really an object of any class). It's up to you to define what does it mean that object is new or not (persisted or not). Again, it's not a form which is persisted.
Btw, you could check for id like this:
{% if entity.id %}{% endif %}
A better solution nowadays (SF3) will be:
{% if form.vars.data.id %}{% endif %}