Created code:

class Api { public $breedName = 'Саванна'; public function showBreed() { echo $this->breedName; } public function showLink() { echo "Вторая функция здесь!"; } } 

I'm trying to use the site.com/api.php/api/showBreed function but I get a blank screen. What am I doing wrong and how to call a function correctly?

Thank!

  • one
    site.com/api.php/api/showBreed thus do not apply to methods in classes - Evgeny Nikolaev

2 answers 2

site.com/api.php/api/showBreed change to site.com/api.php?method=showBreed

in api.php

 if($_GET['method'] == 'showBreed'){ $api = new Api(); $api->showBreed(); } 

    Pure addition to the answer above

     if(isset($_GET['method'])) { $method = $_GET['method']; $api = new Api(); if(method_exists($api,$method)) { $api->$method(); exit(); } } echo '404 error'; 

    So it will be less mistakes