Post by payflow » Wed Jan 27, 2010 4:45 am

In all the controller files I've opened up, I've seen code like this:

Code: Select all

		if (isset($this->request->post['company'])) {
    		$this->data['company'] = $this->request->post['company'];
		} elseif (isset($this->session->data['guest']['company'])) {
			$this->data['company'] = $this->session->data['guest']['company'];
		} else {
			$this->data['company'] = '';
		}
Repeated over and over. A simple in-class function like:

Code: Select all

private function loadDefaultValue($key, $default)
{
	if (isset($this->request->post[$key])) {
		$this->data[$key] = $this->request->post[$key];
	} elseif (isset($this->session->data['guest'][$key])) {
		$this->data[$key] = $this->session->data['guest'][$key];
	} else {
		$this->data[$key] = $default;
	}
}
(Called with $this->loadDefaultValue('company', '');)

Would potentially allow hundreds of lines of code to be removed from the software, improve overall code readability, and reduce the amount of time needed to test. Of course, there might be URL "route" issues (make sure no one can do route=checkout/guest_step_1/loadDefaultValue).

New member

Posts

Joined
Wed Jan 20, 2010 7:13 am

Post by Qphoria » Wed Jan 27, 2010 7:06 am

I too have played with this in the older 0.x version. Basically, since the post fields are (at this point) named the exact same name as the db field, there is really no need for statically listing each. I suppose it could open a can of worms to use a simple key = value method and assume the key name is the field name and the db name exactly. The only place you'd have problems is if you used a different name for a post field. Which could happen I suppose. Or it could be an array type field.

Something to think about tho.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 6 guests