Welcome Guest, Not a member yet? Register   Sign In
Problem with custom helper, any clues would be much appreciated
#1

[eluser]Unknown[/eluser]
Hi all:

I am new to CI and php. I am working on a project that needs a set of common functions to format data. I did the prototype with the functions in the controller. I them moved them to a file "lbfile_helpers.php":

<?php
function timestamp()
{
return date(”Y-m-d H:iConfused”);
}
?>

when I try to call this from a form via submit and a route I get:
Fatal error: Call to undefined method Lblanding::timestamp() in /Users/richard/Sites/CI/system/application/controllers/lblanding.php on line 163

If the function is declared in the class, everything works.

I am sure this is a simple error, but I have tried everything I can think of.

Thanks
Richard
#2

[eluser]davidbehler[/eluser]
Pretty sure you are trying to call the function like this:
Code:
echo $this->timestamp();
try
Code:
echo timestamp();

As you moved the function from your controller to the helper it no longer is a method of said controller but a simple function.
#3

[eluser]Unknown[/eluser]
Thanks much.

It is amazing how you can read the same instructions several times at 1:00 AM and get them wrong every time.

Richard




Theme © iAndrew 2016 - Forum software by © MyBB