Loading models in controllers by extending a custom core class. |
Hello,
I'm currently building an application that uses the same models in different controllers. Instead of using the normal way, being loading the model in the controller i've build a "core controller" (Foundation_controller) which can load models all other controllers extend from this controller in a way. In those extended controllers i load my model the following way: PHP Code: #Controller example PHP Code: #Function to load the models from foundation controller *It' might look confusing here because i load the model in the constructor, but in some controllers i load a specific model (or get the object) inside of a function or at a certain point in a process. Everything works but now i'm concerned this could lead to a potential security risk, or bad resource management , since the models are being loaded "somewhat" globally. Some models are in subfolders and some versions of the app require a different version of a model. Or some app versions don't have some model files at all. (Lite version) The main thing is that each controller in the app extends from Foundation_controller to use the load function, some controllers are being used for pages with "public" access and others are behind a authenticated users part. The main reason why I have the load_model function is that I don't want to repeat code to check if the model file exists, a particular function exists and that the class has already loaded. Also this approach has less chance for typos and if a model path changes less work to refactor. Now I have doubts that this is secure, and I wonder if this is a valid way to load models in codeigniter and that it remains secure and stable / performant. All remarks and suggestions are welcome. Best regards, Bart |
Messages In This Thread |
Loading models in controllers by extending a custom core class. - by bartMommens - 05-25-2019, 03:09 AM
RE: Loading models in controllers by extending a custom core class. - by dave friend - 05-25-2019, 08:37 AM
RE: Loading models in controllers by extending a custom core class. - by bartMommens - 05-26-2019, 03:37 AM
RE: Loading models in controllers by extending a custom core class. - by dave friend - 05-26-2019, 06:57 AM
RE: Loading models in controllers by extending a custom core class. - by bartMommens - 05-26-2019, 10:29 AM
|