Constructing further methods. |
[eluser]CMCDragonkai[/eluser]
For example: Home page has shows a list of stuff from a product database. There is an action (a link that says "change colour to blue") which is supposed to change the colour of all the products. This action then uses url of "home/change_colour" The change_colour method, then sets the variable $colour = blue. What's the next step? Do I simply pass the variable back to $this->index();? Like $this->index($colour);. Is this how one would program their methods for other more complex tasks? That would mean the index method would need to be able to account for any number of variables that may be changed and then construct the page for the view.
[eluser]alexedwards[/eluser]
Generally speaking, the submission to change the colour would be done by performing a HTTP POST request (usually from a form) from your page back to your CI home/change_colour function. One way to handle it would be to store the submitted colour in a session. This will store the chosen colour, along with anything else you want, for a user whilst they're on your site. Additionally, it's always good practice after a HTTP POST to do a redirect too. So something like: Code: $this->load->library('session'); Then in your index function you could just have some code that says: Code: $data['colour'] = $this->session->userdata('colour'); I'd definitely recommend reading up on sessions, and the different types of HTTP requests. Hope that helps
[eluser]CMCDragonkai[/eluser]
Thanks for the information. I will go look up the session doc and OOP doc. |
Welcome Guest, Not a member yet? Register Sign In |