I'm creating a feature on my system for reloading components dynamically so that queries are executed that are allocated to model-layer classes through AJAX requests. However, as I use the MVC standard from the CodeIgniter framework, every request or execution must start from a control class, so I can not execute the queries directly through the class model where it is found.
Would anyone know to inform me of a tool or technique that would facilitate this work for me? Is it possible to execute the queries that are in the model securely directly from the AJAX request, without passing in the controller? Or, if not, is there any tool or function that would allow me to dynamically execute the methods of the model classes from a controller for this function?
For testing purposes only, I started to develop a method in a specific controller to dynamically execute the class and the method requested by parameter via request (http or ajax), however this function will be very laborious if it is used in environment since I have to define parameters and treat them according to the type when concatenating in the string, and worse, how they would be passed via url:
public function requestJson($classe, $metodo, $parametros = array()) {
echo "Executando o método <i>{$metodo}</i> a classe <i>{$classe}</i>:<br>";
$str = '$class = new ' . $classe . '();'
. '$class->' . $metodo . '();';
return eval($str);
}