Welcome Guest, Not a member yet? Register   Sign In
Best way to tackle longer URL with form?
#1

[eluser]gwerner[/eluser]
I'm working up an admin for editing and adding locations and hours. I have a controller for Locations. Within that controller I have the methods index, add, modify and save. I also have methods in the same controller for the hours. They are hours and hoursave for now. The location editor form it's pretty straight forward. It only has three url segments. Pretty simple moving back and forth between the methods without the need for additional URL segments.

Code:
echo form_open('locations/save', '', array('locationId' => $values['location_slug']));

The hours editor form is becoming more complex. My hours method needs three variables $type, $action and $id as shown below. So, if the form doesn't pass validation it will need these three variables passed back to the hours method.

Code:
public function hours($type, $action, $id)
{
  //more code here.
}

What is the best way to handle passing these three variables to the hours method? Should I set the variables in the data array and access in the form_open like so?

Code:
echo form_open('locations/hours/$type/$action/$id');

Or, set them as hidden variables in the form itself?

Code:
echo form_open('locations/hours', '', array('type' => $type, 'action' => $action, 'id' => $id));

Also, does it matter if I have the hours lumped into the locations controller or would I be better off separating the hours into it's own controller? Or, that just a matter of preference? Thanks in advance for any feedback.
#2

[eluser]vitoco[/eluser]
i didn't get you completely, but from what i understood, you need default values in case of the validation fails, so if this is the case, you can set default values for the parameters of the method
Code:
public function hours($type = null , $action = null , $id = null )
{

  // VALIDATE HERE
}

Saludos




Theme © iAndrew 2016 - Forum software by © MyBB