If statements in Controller?

#8
[eluser]jedd[/eluser]
Read other people's code - there's no better way to learn (well, other than writing your own code). But yeah, picking up someone's code and analysing it, assuming you pick a smart person's code to start with, is an excellent learning experience.

There's no shortage of good demonstration code around, too. I hasten to add that my code is not, by any stretch of the imagination, good coode.

Quote:What happens now is that I get "Missing argument 2 for Prod:Confusedhoes()" + "Undefined variable: id" when url "prod/shoes/sandals/" is called, is just fully understable, but how can i get around it?

This is why you have default parameter values in your methods.

Consider .. somewhere in your Products controller ...
Code:
function shoes ( $type = FALSE , $id = FALSE )  {
     if (! $type )
          $type = 'sandals';   // Alternatively you'd set $type to a config entry you have for the default type or just die() here
     if (! $id )
          $id = 1;   // Alternatively you'd set $id to a config entry you have for the default id or just die() here
     }

Note that you can have your parameters in your method declaration set to, say : ($type = 'sandals', $id='1'). You'd do this if you don't care if wrong or absent information was in your URL, and were happy with a hard-coded default value. It's likely that an id of '1' doesn't match the category of sandals, though, so that probably isn't the best approach.

Don't take this the wrong way, but if you're having trouble with these things at the moment, you might want to put off remapping until you're more comfortable with the basic patterns.


Messages In This Thread
If statements in Controller? - by El Forum - 10-20-2009, 12:27 PM
If statements in Controller? - by El Forum - 10-20-2009, 12:33 PM
If statements in Controller? - by El Forum - 10-20-2009, 01:19 PM
If statements in Controller? - by El Forum - 10-20-2009, 01:37 PM
If statements in Controller? - by El Forum - 10-21-2009, 09:47 AM
If statements in Controller? - by El Forum - 10-21-2009, 11:03 AM
If statements in Controller? - by El Forum - 10-21-2009, 12:31 PM
If statements in Controller? - by El Forum - 10-21-2009, 03:24 PM
If statements in Controller? - by El Forum - 10-22-2009, 06:13 AM
If statements in Controller? - by El Forum - 10-22-2009, 08:46 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.