0

I want to create the global function in codeigniter for sending the SMS. Whenever I want to send SMS simply I just call these global function i.e. SMS then where to write these function.

Cœur
  • 32,421
  • 21
  • 173
  • 232
  • You can check this thread - http://stackoverflow.com/questions/804399/codeigniter-create-new-helper , there is written how to create helper class and in which you can create your sendSms method – Armen Nov 22 '16 at 05:56

2 Answers2

0

CodeIgniter comes pre-packaged with a lot of helper functions. So you can make a call to, let's say, site_url() wherever you want across your application. You can write your own custom helpers as well.

Create a sms_helper.php in your application/helpers directory, add your functions, a sms() maybe. Then autoload it in application/config/autoload.php:

$autoload['helper'] = ['sms', ...];

Now, you can call sms() wherever you want.

If you don't autoload it, you need to $this->load->helper('sms'); before you call any helper functions provided by that helper.

Tpojka
  • 6,435
  • 2
  • 25
  • 34
sepehr
  • 13,648
  • 5
  • 73
  • 111
0

You can write this function in the custom helper file in folder application\helpers. In this folder create a file common_functions_helper.php and create a function directly like

function sendSMS($data = array()){
  // function body
} 

and load this file in a function where you want to call this function Like

$this->load->helper('common_functions');

and call the sms function by function name

sendSMS();
Alok Bichhwe
  • 172
  • 2
  • 8