Welcome Guest, Not a member yet? Register   Sign In
Templating App Forms
#2

[eluser]CroNiX[/eluser]
I don't see how you could simplify it much. Yes you could make a helper that outputs the divs with the label and field, but you have other variables. Like you'd have to tell it what kind of field since you are using regular "input" and "password" fields, and probably want others that you aren't showing like textarea, dropdowns, checkboxes, etc. So by the time you create a helper you'd probably have just as much code in order to pass the data to the helper, so I'm not sure it would be worth it. And you'd still also have to pass the fields attributes as they change for each input.

One thing I would generally advise is to not create a variable unless it is going to be used more than once. It can be argued that an exception would be for readability, like a very long array or something. When a variable is created, it takes memory to store that variable and value.

For example,
Code:
$attributes = array('class' => 'strong');
echo form_label('Password', 'password', $attributes);

You aren't using $attributes anywhere else. You are just creating it to pass it, which takes more memory than:
Code:
echo form_label('Password', 'password', array('class' => 'strong'));
which is just as readable and takes less lines of code as well.


Messages In This Thread
Templating App Forms - by El Forum - 12-10-2013, 12:36 PM
Templating App Forms - by El Forum - 12-10-2013, 01:09 PM
Templating App Forms - by El Forum - 12-10-2013, 01:16 PM
Templating App Forms - by El Forum - 12-10-2013, 01:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB