number of model, controller and view |
[eluser]sniperscope[/eluser]
Hello I want to ask number of models and controller. if we have 200 pages web page. do we have to create 200 controller, 200 model and 200 view page? What if we want to use same code in a.php and e.php? If possible, then how? So far i know reach controllers by url segment. so, lets say we have Books |_ book_list.php Author |_author.php and we call book_list.php through example.com/books/ and it loads $this->load->model('book_list'); $this->load->view('books/book_list'); Do i have to create almost same controller and model for author.php as well? Regards
[eluser]sniperscope[/eluser]
what i meant was an example. Let's say we have 200 pages and 10 of them has listing books. Do you create slightly different 10 pages? and 10 models, and 10 controller?
[eluser]InsiteFX[/eluser]
No you would need 1 Controller a Books Model and then you would need one view that you would paginate through the records, using the Pagination Class.
[eluser]davidMC1982[/eluser]
Generally speaking you will have 1 model per database table, one view per page layout on your site (or per part of a page), and as many or as few controllers as makes sense. For example, for a simple site serving static pages you could have 0 models, 1 controller containing 1 function that takes the page name as a parameter, and a view for every page. For a simple ecommerce site you might have 3 models (products, orders, orderdetails), 2 controllers (products and checkout) and 4 views (list_products, view_product, checkout and confirmation). Do what makes sense for your site. Just make sure that you manage data in your models, display data in your views, and use the controllers for managing the interaction between model and view.
[eluser]sniperscope[/eluser]
okay. What if i want to call/run multiple controller or multiple function in one controller from one view. <h1> controller/person/get_person</h1> <h2>controller/person/time_table</h2> <h3>controller/person/some_other_function</h3> How is this possible. Sorry, i am asking too much question but as you may guess i have just started CI and i felt it is soo exciting then cakePHP
[eluser]davidMC1982[/eluser]
Your thinking is backwards. Your example implies that you want to show some info about a person, their associated time_table and some_other_data. Your url could look like this http://www.example.com/person/show_person/45767 Your controller might look like this: Code: class Person extends CI_Controller { I suggest you read the introduction and tutorial section of the user guide to get a better grasp of MVC architecture and Codeigniter.
[eluser]sniperscope[/eluser]
Dear davidMC1982 Thanks for help and reply. My problem is that i am using php about 7 years and 'till now i used regular php (Not OOP) but know i want to learn a framework and it makes me confuse. For example; i still am not able to add and display css/js/jquery into my experimental site. But thanks for reply, let me i start to reading all over again.
[eluser]InsiteFX[/eluser]
For css and jQuery it would be like this. Directory Structure: Code: application For your html: Replace the $ with s in the script tags... Code: <head>
|
Welcome Guest, Not a member yet? Register Sign In |