How to call a. php file function using Apache?

Asked

Viewed 66 times

0

I’m trying to make an api and wanted to call different functions of 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 he calls just what’s at the root of that file, I wish I could 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 someone can help me I’ll be very grateful.

1 answer

0

A friend of mine answered me saying that I would need routes, so I went to do a search and I was able 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=Classvehicles&metodo=getAll'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.