Welcome Guest, Not a member yet? Register   Sign In
Where To Place View Related Function?
#1

[eluser]Md. Iftekharul Islam Sakib[/eluser]
Hi,
I have some function in my project which are used to display Some Common Things Of View.

As Example
Code:
function showTrueOrFalse($myBool)
{
      if($myBool)
           echo "It is True";
      else
           echo "Oops! It is false";
}

If I don’t use this function than I have to write the same code many times. For using these function I just call them from View.

As Example
Code:
<?php showTrueOrFalse(true)?>;

They will only be called from view. But as I have 3 views if I copy this function in both of them it will be a mere code duplication.

I am new to codeigniter. I am not understanding where to put this view related functions. It will be very helpful if any of you help me.
#2

[eluser]vrencianz[/eluser]
Create a helper in the <b>application/helpers</b> directory. See http://ellislab.com/codeigniter/user-gui...lpers.html for details.

For example create <b>utils_helper.php</b> with the content

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function showTrueOrFalse($myBool)
{
      if($myBool)
           echo "It is True";
      else
           echo "Oops! It is false";
}

then call

Code:
$this->load->helper('utils');

from your controller.
#3

[eluser]InsiteFX[/eluser]
How many forum topics are you going to ask this question in?
#4

[eluser]Md. Iftekharul Islam Sakib[/eluser]
@vrencianz, Thank You Very Much. I have solved My Problem with using your advice.

@InsiteFX, As it was my first, I created a topic wrongly in General discussion. Then I created The Topic in Code Section. I am very much sorry for creating multiple post.




Theme © iAndrew 2016 - Forum software by © MyBB