Welcome Guest, Not a member yet? Register   Sign In
number of model, controller and view
#1

[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
#2

[eluser]InsiteFX[/eluser]
Wouldn't author be part of books?
#3

[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?
#4

[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.
#5

[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.
#6

[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
#7

[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 {

    function show_person($id) {

        //Load the models you need
        $this->load->model('person');
        $this->load->model('time_table');
        $this->load->model('something_else');

        //Some code here to get the data you want and put all the data you want in a data array
        //These are calls to the functions defined in your model
        $data['person'] = $this->person->get_person($id);
        $data['time_table'] = $this->time_table->get_timetable($id);

        //Now load the view you want to display this data in
        //Your view will be some html mixed with a little php to display the data
        $this->load->view('display_person', $data);
    }
}

I suggest you read the introduction and tutorial section of the user guide to get a better grasp of MVC architecture and Codeigniter.
#8

[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.
#9

[eluser]InsiteFX[/eluser]
For css and jQuery it would be like this.

Directory Structure:
Code:
application
system
index.php

assets
-- css
-- js
-- img
-- images
-- icons
-- etc...

For your html:
Replace the $ with s in the script tags...
Code:
&lt;head&gt;
    &lt;base href="&lt;?php echo base_url(); ?&gt;" &gt;

    &lt;link type="text/css" href="&lt;?php echo base_url('assets/css/your.css'); ?&gt;" rel="stylesheet" media="all|braille|print|projection|screen|speech" &gt;

<$cript type="text/javascript" src="&lt;?php echo base_url('assets/js/jquery.js'); ?&gt;"></$cript>
&lt;/head&gt;
#10

[eluser]sniperscope[/eluser]
Dear InsiteFX
Thank you so much for help.




Theme © iAndrew 2016 - Forum software by © MyBB