How to call a function from the file.php using Apache?
I'm trying to make an api and wanted to call different functions from the same php file. The way I managed to do it works like this:
<?php
include("ClassVeiculos.php");
$Veiculos = new ClassVeiculos();
$Veiculos->getAll();
And the call is: 'localhost / api'
But so it calls only what is in the root of this file, I wanted to be able to create functions in it, something like:
include("ClassVeiculos.php");
class DAO {
public function getAll(){
$Veiculos = new ClassVeiculos();
$Veiculos->getAll();
}
}
And call as: 'localhost / api / getAll'
But I can't do it, if anyone can help me I will be very grateful.
0
Author: Raphael Villadouro, 2019-11-26
1 answers
A friend of mine answered me saying that I would need routes, so I went for a survey and managed to do it.. getting like this:
include("ClassVeiculos.php");
$nomeClasse = $_GET['classe'];
$metodo = $_GET['metodo'];
$classe = new $nomeClasse(); //cuidado aqui!!!
$classe->$metodo(); //e muita atenção aqui!!!
And in the call: 'localhost / api/?class = ClassVeiculos & method=getAll '
0
Author: Raphael Villadouro, 2019-11-26 00:31:06