Welcome Guest, Not a member yet? Register   Sign In
homemade helper isn't working
#1

[eluser]hht1230[/eluser]
I have functions that are used in several parts of the site to format strings so I thought I would put them in a helper. I created myformat_helper.php with those functions in system/application/helpers and in the controller I do $this->load->helper('myformat') but I get a "Call to undefined function" in the view when I try to call any of the functions. It works fine when the functions from the helper are physically in the view page, so I must not be accessing the helper correctly. Some dumb thing I have overlooked?

Also, why is there no closing ?> in the built-in helper files?
#2

[eluser]hht1230[/eluser]
Sorry, scratch that question. I uploaded the wrong file -- all works as it should now. And I found the answer to the closing tag issue here: http://ellislab.com/forums/viewthread/79395/#398719
#3

[eluser]sophistry[/eluser]
hey! welcome to CI.

you should post your code. it sounds like the view doesn't have access to the functions. what happens when you call the helper functions in the controller right after loading the helper?

BTW, the closing tags were removed in a recent version (1.6.2) (from the changelog)

Quote:Removed closing PHP tags from all PHP files to avoid accidental output and potential 'cannot modify headers' errors.
#4

[eluser]sophistry[/eluser]
darn, not typing fast enough! anyway, glad you fixed it. let us know if you hit anything else (or make anything else!).

also, please post your helper functions here if you don't mind. i'm curious to see what you've come up with.
#5

[eluser]hht1230[/eluser]
Thanks for the welcome and the reply, anyway. I'm so far really loving CI, and glad to see this forum is so active. I don't think my helper functions are anything valuable for anyone else -- they are simple things like

function formatTime($s) {
if ($s == "0001") return ("");
else {
$h = intval(substr($s, 0, 2));
$m = intval(substr($s, 2, 2));
$ms = $m < 10 ? "0" . strval($m) : strval($m);
if ($h == 0) return ( "12:" . $ms . " am");
elseif ($h == 12) return ("12:" . $ms . " pm");
else return ( ($h > 12 ? $h-12 : strval($h)) . ":" . $ms . ($h > 12 ? " pm" : " am") );
}
}

which just format strings that I use in the way that I need them displayed, and I thought I'd try out the helper idea. Not sure if that's the best way, but I like the idea of saving reused functions away in logical groups.
#6

[eluser]sophistry[/eluser]
ok, thanks.

cheers.




Theme © iAndrew 2016 - Forum software by © MyBB