Welcome Guest, Not a member yet? Register   Sign In
How to create Helper File
#1

[eluser]BD-CI-Programmer[/eluser]
Step # 1
Create a file at your helpers folder (system/helpers). File name will be filename_helper.php like this.

Now let create a file name test_helper.php and save it on your helpers folder.

Code:
<?
function hello_nahid()
{
echo "I am Nahid";
}
?>

Step # 2


Create a controller (test_help.php) on you controller folder.

Code:
<?php
class test_help extends Controller
{
    function test_help()
    {

        parent::Controller();

    }

function index()
{

$this->load->helper('test');
echo $str = hello_nahid();

}


}
?>

Now run the application http://localhost/ci/index.php/test_help

Out Put will be “I am Nahid”
#2

[eluser]wiredesignz[/eluser]
Please correct your mistakes, helpers should be located in application/helpers not system/helpers, the Controller class name must be ucfirst ie: Test_help and echo $str = hello_nahid(); may be valid but it is not good style for a tutorial. The helper is also echoing a value rather than returning it to the Controller which makes the echo in your Controller redundant. Not a very helpful helper at all.

Thanks.
#3

[eluser]xwero[/eluser]
BD-CI-Programmer rewriting the user guide to make topics is not a good way to create forum karma. You should have learned that from your post on libraries. If you like to write tutorials make them about what isn't in the user guide or already on the forum.




Theme © iAndrew 2016 - Forum software by © MyBB