Welcome Guest, Not a member yet? Register   Sign In
If statements in Controller?
#9

[eluser]industrial[/eluser]
[quote author="jedd" date="1256178286"]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.[/quote]

Yes sir! Have been going through sample applications and snippets to get more knowledge, but where can I find more info about this specific feature regarding giving funcion variables an initial FALSE value?

Tried to google "default parameter values" but without too much luck.

No offence taken regarding the remapping thing. I was quite certain of an existing and easy way to do what I wanted without leaving the basic features in CI. Many thanks for guiding me into the correct path!


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



Theme © iAndrew 2016 - Forum software by © MyBB