Where to place global functions in codeigniter

前端 未结 4 1612
误落风尘
误落风尘 2020-12-14 02:15

I have created a few utility functions like one h() that acts as echo htmlentities($var) . I want theses functions to be available everywhere . so

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 02:51

    You should include your global variables file in your /application/config/constants.php file. Then move your global function file to /application/helpers folder. Then you should autoload the global functions file. /application/config/autoload.php

    $autoload['helpers'] = array('your-global-function-file.php');
    

    I would suggest not moving anything inside of the system folder project, as upgrading would be an absolute nightmare. Sometimes refactoring your code to conform to CI logic, maybe faster in the long run rather than trying to copy/paste stuff all over the place.

提交回复
热议问题