• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Would like to condense some code.

#18
[eluser]Damien K.[/eluser]
Yes, set_value() form helper function will use post data if available otherwise it will use the default value if provided as the second parameter -- e.g., set_value('email', '[email protected]').

I would imagine that most people in the community use this sort of approach.

If you are using the code I provided before, then set_post() will do all the 'magic' for you and you don't need to pass this data explicitly via $data (there still may be other data you might want to pass via $data). Note again that set_post() is not a CI build-in function--I've extended CI_Input to have this custom-made function to set post data so I don't need to pass it the 'normal' CI-way via $data.

I don't want to encourage you to detach yourself from passing data via $this->load->view('contact', $data), because this is 'common CI practice' and everyone does this! Furthermore, you still need to pass data, for example, page title using this method.

I'm probably only a few out there doing it the way I presented. It saves me a few keystrokes and it is intuitive for me. You should only try my approach if it is intuitive for you too -- don't try to force a square into a circle! There are more than one right way to do things. Feel free to inquire further -- it is a fairly big jump from where you started to the code I provided.


Messages In This Thread
Would like to condense some code. - by El Forum - 09-29-2009, 10:29 AM
Would like to condense some code. - by El Forum - 10-01-2009, 08:53 AM
Would like to condense some code. - by El Forum - 10-02-2009, 10:16 AM
Would like to condense some code. - by El Forum - 10-08-2009, 05:50 AM
Would like to condense some code. - by El Forum - 10-08-2009, 06:10 AM
Would like to condense some code. - by El Forum - 10-08-2009, 07:01 AM
Would like to condense some code. - by El Forum - 10-08-2009, 08:30 AM
Would like to condense some code. - by El Forum - 10-09-2009, 06:42 AM
Would like to condense some code. - by El Forum - 10-09-2009, 09:35 AM
Would like to condense some code. - by El Forum - 10-09-2009, 12:27 PM
Would like to condense some code. - by El Forum - 10-09-2009, 01:19 PM
Would like to condense some code. - by El Forum - 10-09-2009, 02:51 PM
Would like to condense some code. - by El Forum - 10-09-2009, 05:41 PM
Would like to condense some code. - by El Forum - 10-09-2009, 05:44 PM
Would like to condense some code. - by El Forum - 10-11-2009, 12:37 PM
Would like to condense some code. - by El Forum - 10-11-2009, 12:47 PM
Would like to condense some code. - by El Forum - 10-11-2009, 02:58 PM
Would like to condense some code. - by El Forum - 10-13-2009, 08:31 AM
Would like to condense some code. - by El Forum - 10-14-2009, 10:02 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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