Where to put functions / classes? |
[eluser]dharmy[/eluser]
Hi all Am having problems understanding where classes should be kept in CI. I am building an application that markets mobile phones. I would like for all of my functions (i.e. getphone, getdetails etc.) to reside in one class called Mobile - I understand that this file should be called Mobile.php and reside in the controllers folder. Can I then have multiple functions inside Mobile.php? E.g. Code: public function getphone() { Or do I need to put each function in its own class? I'd really appreciate looking at some sample code that works. I've been going through the documentation and google for a few hours, and tried all sorts of variations in the URL to find a test class, but without much luck! I've even messed around with the routes and .htaccess... All I am trying to achieve is the following: Code: http://www.site.com/model/HTC-Desire/ Any ideas? Thanks
[eluser]meigwilym[/eluser]
If you want to achieve that kind of structure then you need to set a few routes http://ellislab.com/codeigniter/user-gui...uting.html In this case something like Code: $route['model/(:any)'] = "mobile/getphone/$1"; Mei
[eluser]dharmy[/eluser]
Thanks - so would I have function getphone in the mobile.php file (in the controllers folder)? Also I presume the $1 refers to the parameter that getphone will accept? Thanks
[eluser]meigwilym[/eluser]
Quote:so would I have function getphone in the mobile.php file (in the controllers folder)? Yes (but as it's a class call them 'methods' to save any misunderstandings). Quote:Also I presume the $1 refers to the parameter that getphone will accept? Yup. You should have Code: public function getphone($phone_name) { In the above case $phone_name would be HTC-Desire. Mei
[eluser]Jason Stanley[/eluser]
You are coming across as an ultra-noob (no offense!) This may be a good place to start with CI if you are new to it. http://net.tutsplus.com/articles/news/co...tch-day-1/
[eluser]vbsaltydog[/eluser]
watch video tutorials read the user guide experiment reverse engineer |
Welcome Guest, Not a member yet? Register Sign In |