So I have library called Engine.php and what it does basically is running
example.com/controller/method/value
So for example if I have
example.com/category/images
it runs the method called "images". But I don't want to add to the code for every single category. I want the method to be a variable (so that I will make it work with db later).
How can I achieve this without changing the Engine? The problem is - some of the pages don't have categories at all. And I don't want to rewrite the Engine itself.
Can I somehow do this in the controller? For example:
I'm entering controller called "category" and if method is set, it searches for this method within the controller (''category'').
This is what part of my Engine.php looks like:
if (isset($url_output[1])) {
if (isset($url_output[2])) {
if (method_exists($controller,$url_output[1])) {
$controller->{$url_output[1]}($url_output[2]);
} else {
$this->error();
}
} else {
if (method_exists($controller,$url_output[1])) {
$controller->{$url_output[1]}();
} else {
$this->error();
}
}
}
So basically, as you can see:
$controller->{$url_output[1]}();
$url_output[1] = the name of the method in controller named $url_output[0].
What I want is:
public function $category() {
echo $category
}
You know what I mean?