Call function in PHP via Link using MVC

0

I am having difficulty / problem to request a function in PHP: Home This function below is located in a class inside the lib folder.
Language.php

<?php

namespace app\lib;

class Language {

    public function setLingCookie(){
        if(isset($linguagem)){
            setcookie("IDIOMA", $linguagem, time()+3600, "/", "localhost/");
            echo 1;
        }else{
            echo 0;
        }
    }
    .
    .
    .
}


My difficulty is to trigger this function through my page, and I will trigger this from a Link. Home I am using the Composer and I am using the Composer / em> only for Autoload .

    
asked by anonymous 25.07.2018 / 15:09

1 answer

1

You need a page, for example, setcookie.php , and on this page, you should instantiate the class you created, something like this:

$l = new Language();
$l->setLingCookie();

Are you using any framework? Depending on the framework, there might be ways to access this function by routes, but since you did not mention any, the method would be for a php file that instantiated that class you did

I hope I have helped !!

    
25.07.2018 / 20:07