Question: I am trying to make some helper in view part ,so that I can share the common logic in the view part of whole project .

But it seems in CI ,there is no such concept ,like in CakePhp ,i can use the custom helper .

I have searched a lot but not getting any proper results to carry out .

Below I have mentioned some codes of my view parts.

```html
<?php  $dt2 = strtotime($single->time_stamp);
 $dt1 = strtotime(date("Y-m-d H:i:s"));
  echo (int)(abs($dt1 - $dt2)/(60*60));?>

```

I have used this codes in view ,but I want to reuse it .

I want to call a custom helper passing one argument ,as another one is the current date.

Any suggestion?

Thank you in advance .

Answer: 
This would be your helper application/helpers/time\_diff\_helper.php: 

```
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

if (!function_exists('time_diff'))
{
    function time_diff()
    {
        $dt2 = strtotime($single->time_stamp);
        $dt1 = strtotime(date("Y-m-d H:i:s"));
        return (int)(abs($dt1 - $dt2)/(60*60));
    }
}

```

You would then load it in your controller: 

```
$this->load->helper('time_diff');
$tdiff = time_diff();

```

If you load it into your controller, you should also be able to use it from within your views. People would argue that business logic doesn't belong in views, that view are juts there to format the display. Is your function part of the business logic or just part of the layout... ? I guess it's a matter of interpretation. I would call it in the controller and pass it to the view. 

```
$data['time_diff'] = time_diff();
$this->load->view('myscreen1', $data);

```
Yes its very simple no need to do some extra work .

Just load the helper created by you either in controller or in view or in autoload.php ,

I loaded it in autoload.php 

```html
$autoload['helper'] = array('url','string','form','common_helper');

```

If you wish to load it in controller/view ,then follow this synatx.

```html
$this->load->helper('common_helper');

```

Then the next step is to call the helper , as per my requirement i need to call it from view so the code will be .

```html
  <?php        echo time_diff($test->time_stamp);    ?> HOURS AGO

```

Just call the function only ,the calling is quite easier then cakephp :).

Then it will work fine .

it may be helpful to some one like me ,who is new to CI .
Happy coding :)