Welcome Guest, Not a member yet? Register   Sign In
Multiple helpers not loading properly (specifically form and url)
#1

[eluser]Jay Turley[/eluser]
I don't know if this is due to my CI noobness, but just in case, I'm going to post it here.

In my controller, I have the following:

Code:
function index() {
        $this->load->helper('form','url');
        $this->load->view('user_form');
    }

When I create the view, the following code breaks. By this I mean that the rendered html source terminates with the submit tag. There is nothing following it, no anchor, no html closing tag, no nuthin'!

Code:
$attributes = array('name' => 'new_user_form', 'id' => 'new_user_form');
    echo form_open('user/create', $attributes);
    echo form_label('Username', 'username');
    $inputData = array(
        'name'        => 'username',
        'id'        => 'username',
        'maxlength'    => '20',
        'size'        => '20',
    );
    echo form_input($inputData).'<br />';
    echo form_label('Password', 'password');
    $inputData = array(
        'name'        => 'password',
        'id'        => 'password',
        'maxlength'    => '20',
        'size'        => '20',
    );
    echo form_password($inputData).'<br />';
    echo form_submit('addnewuser', 'Create Account');
    // THIS IS WHERE THE CODE BREAKS!
    echo anchor('', 'Cancel');
    echo form_close();

After experimenting, it appears the only thing that fixes this issue is to load the helpers separately. With no change to the code at all, suddenly everything works.

Code:
function index() {
        $this->load->helper('form');
        $this->load->helper('url');
        $this->load->view('user_form');
    }

I searched the forum, but found no reference to this.

Thanks!
#2

[eluser]ontguy[/eluser]
It should be:
Code:
$this->load->helper( array('form', 'url') );
#3

[eluser]Jay Turley[/eluser]
Oh, and don't I feel stupid for forgetting that </shame>
#4

[eluser]Derek Allard[/eluser]
Hey Jay, not a problem. I did that just a few weeks ago... and I work with that code for like... 13 hours a day Wink




Theme © iAndrew 2016 - Forum software by © MyBB