How to use `Composer` to add Codeigniter helper in a project?

1.4k views Asked by At

In order to learn how composer works

I created composer.json to download codeigniter with all dependencies

{
    "require": {
        "rogeriopradoj/codeigniter": "2.1.4"
    }
}

then created vendor directory using composer

After loading all these I want to just use form helpers that comes with codeigniter and I want to all this using composer(to know how composer works).

I created index.php having the following code and also have included require 'vendor/autoload.php';

<?php
// file name : index.php
require 'vendor/autoload.php';


class A extends CI_Controller
{   
    public function home()
    {
        $this->load->helper('form');
        echo form_open('email/send');

        $data = array(
                      'name'        => 'username',
                      'id'          => 'username',
                      'value'       => 'johndoe',
                      'maxlength'   => '100',
                      'size'        => '50',
                      'style'       => 'width:50%',
                    );

        echo form_input($data);
        echo form_close("</div>");      
    }

}

$a = new A;
$a->home();

?>

When I visit 127.0.0.1/index.php I get the following error

Notice: Undefined property: A::$load in C:\xampp\htdocs\M\index.php on line 14

Fatal error: Call to a member function helper() on a non-object in C:\xampp\htdocs\M\index.php on line 14

So its not working the way I wanted,anyone please explain what's wrong?

Update

After including form helpers but still getting this error,I have included vendor/autoload.php

Fatal error: Class 'CI_Controller' not found in C:\xampp\htdocs\M\index.php on line 7

1

There are 1 answers

4
Clément Malet On

You've not set $load. It's like your doing something like null -> helper (); which explains the "call on a non object" error.

Edit : For your Class not found error, you could give a look at this :

Codeigniter Command line error - PHP Fatal error: Class 'CI_Controller' not found