I can't understand how to use MVC ... |
[eluser]Ali Kimiagar[/eluser]
Hi, I've got a question ... Think , we've got a simple website witch has top menu , sidebar and content area. Someone wants to access http://my-codeignitor.com/content/show/1 How can I load other views such as top menu , side bar beside the content!? You know I'm confused because these (top menu , sidebar ) doesn't belong to content controller and model ...
[eluser]Bart v B[/eluser]
Wel, it is not complicated. The controller controles things. The model does the things. The view is for presentation. So with that knowlege we can do a step more. The presentation with alway's the same menu and top, then you can do that like this: create in the view folder a new foldes named: includes. So /application/view/includes/ In that folder create a new php file called: template.php And add some code like this: Code: <?php in the includes/topmenu.php you put the code from your menu. in the includes/sidebar.php you put the code from your sidebar $main_content... // later In the includes/footer.php you put the code from your footer. (something like </bode></html> Now we have a variabele to do someting with. in your controller: Code: <?php Now when you create a content.php in your view folder. Code: <h1><?php echo $hello?;></h1> And now you should see 'Hello Codeigniter' when you call it from your url.
[eluser]Ali Kimiagar[/eluser]
Bart v B: Well , first of all thanks. you mean I don't have to write controllers for top menu and sidebar!? our imaginary top menu and side bar are not static ... they get their data from database.
[eluser]Bart v B[/eluser]
Ok topmenu and side bar are not static.. How are they build on? I mean, they are depending on the controllername or something? Then you can also do that the same way as i explained. Other option is to use a template library. for example https://github.com/philsturgeon/codeigniter-template/ In that case you can do something like this: http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY I don't know how complicated your site is, but if there ar just a few classes, models, and view files, then you better off with my first example.
[eluser]Ali Kimiagar[/eluser]
[quote author="Bart v B" date="1312586404"]Ok topmenu and side bar are not static.. How are they build on? I mean, they are depending on the controllername or something? Then you can also do that the same way as i explained. Other option is to use a template library. for example https://github.com/philsturgeon/codeigniter-template/ In that case you can do something like this: http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY I don't know how complicated your site is, but if there ar just a few classes, models, and view files, then you better off with my first example.[/quote] Thanks for everything ... You're information is really useful.
[eluser]Bart v B[/eluser]
Ok, i think i got the point.. you mean something like this? your model test_model.php Code: <?php the controller: Code: <?php views/includes/topmenu.php Code: <?php As you see, you don't have to create a new controller, only some tweaking with the variabele. EDIT something strange is going on the forum.. can't make an hyperlink
[eluser]Ali Kimiagar[/eluser]
Bedankt my Dutch friend, it's what I want ... P.S : What is that link!?
[eluser]Bart v B[/eluser]
You speak dutch? what do you mean with that link? i can not make an hyperlink tag here.. so the code breaks..
[eluser]Ali Kimiagar[/eluser]
[quote author="Bart v B" date="1312588844"]You speak dutch? [/quote] I wish I could speak Dutch , Deutsch , Italian , Spanish and ... I as a Persian would love to speak foreign languages. Code: what do you mean with that link? The way that you introduced me is kinda useful ...
|
Welcome Guest, Not a member yet? Register Sign In |