help me to organize my code without to break mvc pattern rules. code work, help is needed to organize it. |
[eluser]zoreli[/eluser]
I am relativly new in mvc pattern, but not that new in php programming. I start to rewrite my own cms with codeigniter and I have some doubts about how to organize my code in proper way, so I need help: Code works fine, my problem is how to organize it. Question 1: In the back office administration system I have different modules like faq, news, products, projects, services, articles etc.. Should I have it all in one controller? I start to put everything in one, but it starts to become huge, and I am thinking now to make separate controller for faq, another for the news module etc. One more thing that lead me to this decision is that I will not use all modules(FAQ, products, projects...) in every projects, so it sound logically to have one controller for each module than one huge controller for whole back office. Question is am I breaking the mvc logic with creating more than one controller? What is your opinion? Question 2: I have the following model: Code: class DeleteRecords extends CI_Model Here is my controller: Code: public function deleteUser() And here is second controller: Code: public function deleteFaqCategory() Now, the question here is: Am I repeating my self here? I can use one controller to delete any records from any table and after deleting the record, I can redirect him anywhere I want. Any advice will be deeply appreciated. Regards, Zoreli
[eluser]Mauricio de Abreu Antunes[/eluser]
Can you group your all DML statements in your MY_Model? :-)
[eluser]zoreli[/eluser]
I am afraid that my knowledge is not on that level at this time. I will certainly try that after some months, but for the moment, trying to have something to work with for my customers. I am following closely the videos on codeigniter.tv and those people are doing great job, but I am not on their level. My code must be reusable as much as possible, since that will allow me to work faster, therefore offer lowest possible prices. Sure enough, I am trying to not breach any mvc pattern rules. Regards, Zoreli
[eluser]Mauricio de Abreu Antunes[/eluser]
https://github.com/jamierumbelow/codeign.../README.md Read this. This code is reusable. :-) And it's coded by: •Phil Sturgeon •Dan Horrigan •Adam Jackett Take a look at this, please. I'm using this in my APP and works fine. * Think simple. Code: class MY_Model extends CI_Model { I guess in your model your codes are not reusable. Like: Code: class User_model extends CI_Model { And you have other classes doing the same stuff again, again and over and over again... :-)
[eluser]zoreli[/eluser]
Hi Mauricio I have seen the videos on Codeigniter.tv about my model, but I am afraid I am not on that level yet. Seem hard for me to work with something on daily basis that I do not understand. Can you please try to answer my 2 questions? Regards, Zoreli
[eluser]Mauricio de Abreu Antunes[/eluser]
Answer for question 1: Yes, you need one controller for each page, my friend. faq.php (controller for Faq_model.php) about.php (controller for About_model.php) users.php (controller for Users_model.php) Answer for question 2: You, you are repeting yourself.
[eluser]zoreli[/eluser]
Hi to everyone Thanks for the responses & advices. So I guess my only way is to go with MY_Model solution huh? Gulp... :ohh:
[eluser]Mauricio de Abreu Antunes[/eluser]
I can help you with your MY_Model. Send me a private message. :-) |
Welcome Guest, Not a member yet? Register Sign In |