• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI4 controller error with built-in php class (intl)

#1
this my code

PHP Code:
46     public function view_receipt($id)
47     {
48         $data['receipt'] = $this->company_model->get_receipt($id);
49         $data['receipt']->description explode('^'$data['receipt']->description);
50         $data['receipt']->price explode('^'$data['receipt']->price);
51         $data['receipt']->quantity explode('^'$data['receipt']->quantity);
52         $data['company'] = $this->company_model->get_my_company();
53         $credit_term = new NumberFormatter("en"NumberFormatter::SPELLOUT);
54         $data['credit_term'] = $credit_term->format($data['receipt']->credit_term);
55         echo view('templates/receipt'$data);
56     

at line 53 i try to use NumberFormatter class which is built-in php by enabling intl extension.
working fine in php CLI.

but issue an error when use it in controller.


Quote:Error
Class 'App\Controllers\NumberFormatter' not found


APPPATH\Controllers\Home.php at line 53
Reply

#2
Add \ in front of it to use native PHP-functions.

\NumberFormatter
Reply

#3
(07-17-2020, 02:44 AM)jreklund Wrote: Add \ in front of it to use native PHP-functions.

\NumberFormatter
thanks a lot.

as far i remember, in ci3 we dont hv to put it.

*note to other:
make sure to put \ to both class name like this -> $credit_term = new \NumberFormatter("en", \NumberFormatter::SPELLOUT);
Reply

#4
That's correct. CI3 don't use namespaces, so everything are global. Now it will try finding the closes match first.
Reply

#5
Just to add:
a good IDE will provide you with tons of help when it comes to namespacing stuff.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.