php - stuck in a rut, need help breaking through to the next level -


I am working on a humble website with my usual, self-taught PHP skills, and the current interface structure Of:

  & lt ;? Php if (a) {$ output = some funk (a); } And if (b) {$ output = other Func (b); } And if (c) {$ output = still african (c); } And {$ output = 'default stuff'; }? & Gt; & Lt; Html template top off & gt; & Lt ;? Php $ output echo; ? & Gt; & Lt; / Html template bottom half & gt; This was the first time, and seemed very well arranged, but the required functionality has increased from one aspect of 10 and it is rapidly turning into a seamless, embarrassing mess. And I do not know how to get out of it.  

I think that the work that is called for each situation is quite well written and focused, but has been in some disadvantage of how to handle mid-step between the user. And manage returns.

I think MVC is a solution? But I have a hard time getting out of here ...

I apologize for any headache or unpleasant memories that can be inspired by the above code. Thanks for your time.

You think that a lot of people do this, a bigger and / or case statement that increases Continues to All those "if" checks can take time. MVC is definitely a great way to go, but there are several ways to apply it. I would also recommend the front controller design pattern, which is usually used with MVC.

One way to change how you are changing things is to switch to a defined list of "verbs" using an associative array. And your tasks are included in this. After this you can have many functions, variables and other resource codes.

  $ actions = array ('a' => 'action1.php', 'b' = & gt; 'action2.php', 'c' = & gt; 'action3 .php ',' default '= & gt;' action_default.php '); If (isset ($ actions [$ _GET ['action']]) {included ($ actions [$ _GET ['action']]); } Other {Include ($ action ['default']); }  

Then your "index" file is just a routing tool, which is a much higher front controller concept.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -