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


Messages In This Thread
CI4 : I try to add a function in a helper - by kilden - 12-28-2020, 10:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB