If you are using admin generator in symfony 1.4, i bet you will have the problem to customize admin generator listing to show data from foreign table. It’s common for us to display data from different tables within a listing.
To customize admin generator listing to show foreign tables data, follow the steps below:-
Advertisements
- Let’s say we have 2 tables user_logins and user_profiles tables that store user login and their profile details.
- I’ve a user_login module that generated thru the admin generator
- Now i want to customize my admin generator listing to display some user_profiles data. Let say we only want to display 3 columns in our listing eg: user_id, user_name, user_profile_gender
- To do this, first we need to edit the generator.yml
list: display: [user_id, user_name, _user_profiles]
* if you notice, i put a underscore at the user_profiles field.
- Now create a file name it _user_profiles.php in the module templates directory with the content below:-
<?php echo $user_login->getUserProfile()->getGender(); ?>
* Make sure you declare the correct relationship between the user_login and user_profiles table. else you will get error when you call getUserProfile().
- Now, refresh your user_login module listing and you should see the gender is displayed within the listing.
* there might be a better solution out there, if you found one remember to share with the others!
Related posts:
Symfony: How to escape hash # character in yaml
Contact Form 7: Clear all field except specific after submission
Create Gmail with plus addressing to prevent spam
PHP Programming: The difference between require() and include()
How to publish blogger content to my domain
How to convert Youtube video to IPod / IPhone (mp4)
How to remove newline character in PHP
How to write robot.txt to control search engine spider
Share this with your friends:-