New to CodeIgniter--need some help incorporating some existing classes |
[eluser]jprateragg[/eluser]
I've developed an application for my company that analyzes financial information. The bulk of this application consists of three classes: one parent class and two child classes. Code: //retrieves "meta" information about an analysis At the top of my pages, I initiate the Analysis class, then initiate one of the child classes depending on the type of analysis the selected analysis is (each class has the same methods, but each have different calculations). Is it possible to incorporate this into a new CodeIgniter project? Would these be a custom library? A model? How would I go about initializing the correct library--I must initiate a new Standard or Consolidated object based on the type of analysis that's selected. I like the layout of CodeIgniter and feel it would be better suited for my needs, but I want to make sure I can incorporate this still. Thanks!
[eluser]solid9[/eluser]
/application/core/ MY_Controller Code: <?php /application/controller/ Standard Code: <?php /application/controller/ Consolidated Code: <?php Not tested but try.
[eluser]solid9[/eluser]
Standard and Consolidated classes are optional. You can put them in /application/library/ if you like.
[eluser]jprateragg[/eluser]
So I'm assuming MY_Controller would contain the methods and properties for my Analysis class, correct? Would it be better to make the Standard and Consolidated class libraries instead? I may need to use them in different controllers. Since these classes are primarily responsible for generating values from a database, would they be better off as models instead? Or libraries?
[eluser]solid9[/eluser]
If Standard and Consolidated classes are for database querying. Then better use MY_Model instead of MY_Controller Here watch a video tutorial regarding MY_Model. http://codeigniter.tv/videos/keywords/MY_Model
[eluser]kostyak[/eluser]
Hi, jprateragg! Recently I had deal with question like yours. And what I am thinking about it now. According to the MVC pattern, all your programm’s logic must be in a model. And controller must play role to interaction between user and model through views. So, for you will be the best to put all your classes to models. for instance: 1. Make file MY_Model.php and put it to the ‘application/core/’ Code: <?php a. Standard_model.php: Code: <?php Code: <?php
[eluser]jprateragg[/eluser]
Thanks solid9 and kostyak for your suggestions! I have decided to put the main Analysis class in MY_Model, create a Standard and Consolidated model (in application/models), and have those classes extend the MY_Model class instead of CI_Model. This way in my controllers and I just load the Standard or Consolidated model and have access to all of the meta models. Thanks again! |
Welcome Guest, Not a member yet? Register Sign In |