Welcome Guest, Not a member yet? Register   Sign In
CI4 : I try to add a function in a helper
#1

Hello,

Following the documentation I've tried for the first time to extend an helper...
So I've created a file 'text.php' (with the same name as the helper 'text') like this :


Code:
<?php
function format_price($number){
  return (substr($number, -2)==00)  ? substr($number, 0, -3).'.-' : sprintf("%.2f",($number));
}
?>



I put it in app/Helpers, but when I tried to call it in a Controller :


Code:
helper('text');
$data['price'] = format_price(45);


I've got an error like this (strangely with no controller's name) :
Call to undefined function App\Controllers\ctrl_web\format_price()


I don't understand what I do wrong... I've tried to create a new helper ('text2.php') without success, too.
Thank you for your lights and I wish you a merry Christmas and a happy new year !
Reply
#2

Name the file as "text_helper.php"
Reply
#3

oh... ! I feel so stupid... hum hum... Well thank you very much ! It was so simple ! :-)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB