4
I am creating a feature in my system for dynamic component reloading, so that queries are executed that are allocated in model layer classes, through AJAX requests. However, since I use the MVC standard from the Codeigniter framework, any request or execution must start from a control class, so I cannot run the queries directly through the model class where it is.
Would anyone know me a tool or technique that would facilitate my work? Being possible to execute the queries that are in the model in a safe way 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 model class methods from a controller to this function?
Just for the purpose of testing, 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), but this function will be very difficult to use in production environment, since I have to define parameters and treat them according to the type when concatenating into 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);
}
The idea of MVC is for all requests to pass through a controller. Codeigniter already does a lot of magic by mapping controllers with URL routes. The right thing to do is to make model calls in your controller, or simply abandon MVC.
– gmsantos