简体   繁体   English

PHP:继承逻辑(扩展)

[英]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). 事实:我开发了一个网站(带有symfony),允许玩家搜索球队(例如工作委员会)。 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....) 这些问题我想要的网站,以更加准确,使自定义窗体为每个玩家根据游戏(例如,对于那些谁玩“英雄联盟”,他们将有3点更多的信息,以填补.... )

The solutions? 解决方案?

I'm currently developping 1 module per game in order to take in consideration the specific criteria for specific games. 我目前正在为每个游戏开发1个模块,以考虑特定游戏的特定标准。

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. 破坏:每个模块之间90%的代码相同。 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. 我以前从未玩过它,所以我不知道在我的情况下是否可以在整个游戏系列中坚持使用1个模块并考虑游戏的特定标准。 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(); ) 在那种情况下,这意味着每个游戏都有1个模板,并显示具有正确访问者的正确模板,例如( $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 解决方案1

Create a 2 form process. 创建一个2窗体过程。 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 解决方案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 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. 还有其他方法可以实现,但是首先想到这两个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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