Admin Generator Tips And Tricks

Ok, so lets talk about admin generator – usefull tool which Symfony provides for auto-creating interface according to the structure of the data used in the frontend application.
Of course, you are welcome to?аread?аofficial?аSymfony manual here, e.g. here:

But as it often comes – the real life is a real life and sometimes it happens to be different from what they wrote in manuals.?аYou?аmight?аalso?аuse?аSymfony’s?аforum to find some helpful tips:

But I would like to consider here one real-life example. For instance we have User table and need to provide users management functionality in our backend. Sure thing we just may use the default code generated with Symfony backend generator tool. But what if we have some relations between User table and a couple of the other tables (references). Btw, I would like to share with you one usefull tip about references – I’m trying not to keep these reference tables separately (you know how this may be – today we need only statuses for users and tomorrow it will turn out we also need to add user titles, etc). So in order do not create each time new reference tables – I keep all of them into single table ref where I have fields “tbl_name”, “fld_name”, “value” etc. So that it means when I need to create a new reference table I just create new records into my “superref” table and that’s all.

Anyway, we’ve been started to talk about admin generator and I’d like to show you up here which way we can customize generator.yml file and also use just described “superref” functionaly right there.

First of all what if we need to add custom filter with users statuses which are defined into our “SuperRef” table? It’s very easy – just add into generator.yml the following line:

filters: [_status]

then go into templates folder and create there _status.php file which has the meaning all status values loader:



Then the other challange – we need to tie together superref table and record edit stuff. That’s sooo much easy with backend generator, just use the following syntax:

status_id: { params: related_class=RefStatus }

Well, the other usefull thing we may put at the same section is newpassword field (this is needed when you provide the way for admins to change user passwords from backend). So if you want this just add the following line:

newpassword: { name: Password, help: Enter a password to change it or leave the field blank to keep the current one }

Well, there is so much else I’d like to share with you but it’s time to drink some coffee.
Lets continue in a while my friend.

Leave a Reply

Your email address will not be published. Required fields are marked *