Pre-configuration of functions

0

Hello, I have a Facebook BOT and I created a function called sendMSMS (); and within it paço 2 parameters, the facebook id of the user and the message to send but in all the code I use quite a few times this function and I sometimes forget to pass the facebook id, it has as already define in the beginning the id of the facebook?

    
asked by anonymous 12.06.2018 / 16:41

1 answer

0

You can do this in a few different ways.

DEFINE A CONSTANT or variable and then call it in your code. Ex.:

<?php
define("ID_FACEBOOK","SEU_ID_AQUI");
...
enviaMSG(ID_FACEBOOK,"Você está procurando por um hotel?");
?>

Create a CLASS for your related functions and then be able to use the saved data within it. Ex.:

<?php
class uteisFacebook{
    public $id_facebook="";

    public function enviaMSG($msg){
        ... sua função aqui, mas quando for chamar o ID use: $this->id_facebook
    }
}
?>

After you configure the class in your code, if you have a configuration file that is called on every page you can do it inside it, so you do not have to reconfigure it all.

<?php
// Inclua o arquivo da classe:
include("uteisFacebook.php");
// Chame a classe e defina suas variáveis
$facebook=new uteisFacebook();
$facebook->id_facebook="defina_o_id_aqui";
?>

And finally to call the function:

<?php
$facebook->enviaMSG("Você tem um tempinho para falar do nosso senhor e criador, Markinho da galera?");
?>

Well, these are just examples to help you get where you want, but in the case of using class I recommend giving a better search on how to build a class .

    
12.06.2018 / 16:59