user guide, faq and layouts - I'm lost :( |
[eluser]peter222[/eluser]
I looked for good PHP framework. Google "said", that CI is very good documented so I decided to try it. Since three days I try to find basics info like layouts with dynamic partials. 1. No info in main user guide. Some words about multiple views but I still don't know how to load dynamic data to header, footer, etc. 2. Wiki - no FAQ on home page of Wiki, why?. I found it only by google (http://codeigniter.com/wiki/FAQ/)... 3. ...this FAQ says now "Version 1.6 (Released January 31, 2008) has support for multiple views." So I see that rest of section is “old school” (depraced?). Ok, but go back to point 1. 4. Some examples in forum says "$page = $this->load->view("default/header.php", null, true);" but no info in user guide what is 'true' parameter. 5. I found "layout library" but still can't understand how to use it with more partials like header, footer, navigations... I'm really annoyed, can't start because I can't see actual orderly FAQ to 1.6.3 and good documented basics like layouts with dynamical partials. I don't want to waste time for reading of hundreds posts in forum to find best practices. Most of them are not actual I belive. So, I suggest to put official info in user guide or FAQ, how to use it in CI. I'm beginner PHP programmer, maybe advanced users only can use CI?
[eluser]Pascal Kriete[/eluser]
First things first, welcome to CodeIgniter, I'm sure we can get you sorted out so you can start with the real work. I think in this case you're looking for something that isn't there (I really appreciate that you did your homework though). There is no 'official' way to build your output. It's totally up to you. In a very basic fashion, CodeIgniter lets you do 3 things with views: 1. Load them sequentially: Code: $this->load->view('header'); 2. Nest them Code: $this->load->view('template') 3. Return a string (that magical 3rd parameter - documented here) Code: $string = $this->load->view('content', $data, TRUE); The second parameter is data you want to pass to a view. It should be an associative array, and the array keys become your new variable names. It's available to all nested templates, so you don't have to pass it in again. How you setup your app is up to you, it will probably be a mixture of the 3. I personally like to make a template library. Does that help?
[eluser]SpooF[/eluser]
Its all there, you just have to look deeper http://ellislab.com/codeigniter/user-guide/ - Click the table of contents in the upper corner http://ellislab.com/codeigniter/user-gui...views.html Quote:Adding Dynamic Data to the View
[eluser]peter222[/eluser]
Thanks for answer but both posts are identical as many infos which I described before. Maybe I can't understand something very clear for You but my brain is still blocked inparo: $this->load->view('header'); $this->load->view('content'); $this->load->view('footer') Where in Your example dynamically data is transferred to header, footer? It was my main question. SpooF: I really know this part of user_guide (multiple views). But like above. Where is data transferred to header and footer in this example? Maybe my question was not clear, I would be very graceful if somebody write me a full example, how should look files: header controller (with some dynamically data like selected position of menu) header viewer (how to display dynamically transferred data) content controller (with some dynamically data) content viewer (how to display dynamically transferred data) footer controller (with some dynamically data like contacts with different emails dependent of section) footer view (how to display dynamically transferred data) and main, in result: layout - how to use it in any controller/viewer withs all components above (header,content, footer) I'm sure that many, many people will be happy to see full example, not only fragments because many beginners dont't understand how to join it all (sorry for my english).
[eluser]SpooF[/eluser]
Have you checked out the video tutorials on the main page? Main reason I ask is because I think your off to the wrong start on how a controller is used. A controller is a way to organize parts of your site such as a blog, gallery, and such. Not so much particular parts of a page. Even though it can be using some custom libraries. The tutorials on the main page will give you an amazing start into Code Igniter. http://codeigniter.com/tutorials/
[eluser]andreagam[/eluser]
Hi Peter222, the key is your controller. Let's have a minified example: Code: <?php The "_view" files are basically HTML files, where dynamic data comes from the controller. For example, to retrieve the Title in your header_view.php or home_view.php you just echo like that: Code: <title><?=$title?></title> I hope that helps. Enjoy Codeigniter
[eluser]peter222[/eluser]
Thank You both! still no full example, but i catch it!! SpooF: I watched tutorials many times, but I think procedural PHP still so it was all new for me. Yes, I persisted that all view must have own controller - It was my main mistake. CI andrea: it was still incomplete example but thanks to You and SpooF i finally catch it )) All works now, My full minified example, for other people whicth has problem like me to understand idea: in config/routes.php i changed line: Code: $route['default_controller'] = "site_controller"; Then, controller: controllers/site_controller.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); and views: views/header_view.php Code: <html> views/footer_view.php Code: <div id="footer"> views/layout_view.php Code: <?=$header?> It works for me, maybe something need any correct, let somebody correct me. Thanks again all for help!
[eluser]sophistry[/eluser]
nicely done, CI denizens. this thread exemplifies the patient and helpful spirit of the devs that surround and support this framework. I've put a link to this thread in the Views section of the FAQ.
[eluser]Phil Sturgeon[/eluser]
[quote author="peter222" date="1218042772"]Thank You both! still no full example, but i catch it!! [/quote] Instead of doing this in EVERY controller, you can google search for MY_Controller to learn how to set default data for your entire app.
[eluser]Unknown[/eluser]
Hi all. Am new to CI and i have done exactly as mentioned above. I have many views such as header, footer, main_content and sidebar. What i am interested is in getting dynamic content for all these. For example, i have home controller, where i call all the views i.e(header, footer, main_content and sidebar). All these are displayed in home.php view. So far so good. Quote:Now i want to get data for all these views (header, footer, main_content and sidebar) from database. How do i do it? Where should i write the code to query db for each view. Should it be in home controller or should it be directly in header view? Quote:Also, i have another page say "about us" and the link is in header. How do i keep the layout of this link same as the home and get different data depending on the link. What i want to know whether i should create another controller, view and how the flow will be?.. Thanks |
Welcome Guest, Not a member yet? Register Sign In |