简体   繁体   中英

PHP : inheritance logical (extends)

This may sound as a non related coding question but it's directly related :

The facts: I've developped a website (with symfony) which allows players to search for a team (like a job board). It makes one module only.

The problems I want the website to be even more accurate and make a custom form for each players depending on the game (for example, for those who play "league of legends" they'll have 3 more informations to fill up....)

The solutions?

I'm currently developping 1 module per game in order to take in consideration the specific criteria for specific games.

Advantages : The player enters the informations in relation with his game and does not see/interact the other criteria

Disavantages: 90% of the code are the same between each modules. It takes more time.


  • Inheritance

I never played with that before so i don't know if it's possible in my case to stick with 1 module for the entire game collection AND taking in consideration the specific criterias for games. In that case it would mean to have 1 template per game and displaying the right template with the right accessors like ( $this->getCV()->getPseudo(); / $this->getCV()->getGame()->getSpecificCriteria1(); )

If I have read your question correctly, you want to show additional fields for each specific game.

Solution 1

Create a 2 form process. After your first form, you could redirect the user to a second form which depends on their answers. To do this, in your first form, use a redirect to send the user to a game-specific second form.

Solution 2

Pass the name of the game to the template and show a customised partial for the extra form fields. For this you will need a Url with a game parameter like this:

www.example.com/form/show/:game_identifier

Then in your action, read the parameter and pass it to your template. In the template, show a partial dependant on the game that was passed through. So only show the extra fields if a specific game was chosen before hand.

There are further ways to accomplish this but these 2 sprung to mind first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM