Where do you put header.php and footer.php? |
[eluser]Carlos Mora[/eluser]
@jason, I've started using you template and, as bengrice said, $data appears to be out of scope. I'm not sure wich is the best way to pass the full $data array to subviews, but may be that the real $data should be in an elementt of original array, like in <code> function index() { $data["title"] = "Clientes"; $data["heading"] = "Lista de clientes"; $data["query"] = $this->db->get('clientes'); $view_data['page'] = 'cliente_view'; // pass the view to use as a parameter $view_data['data'] = $data; // pass the real data so it is declared as $data $this->load->view('container',$view_data); </code> Another solution may be use use global $data; inside container.php to bring back $data into scope. Both solutions worked here, but I'll appreciate the advise of an expert, in particular with the usage of global $data. Best regards. Carlos
[eluser]bengrice[/eluser]
hi carlos, just encase you missunderstood. i got an error if i tried to pass through the data var. if i just left it off everything passed through as normal eg this is my simple container view Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> as you can see i haven't passed through the second variable the $data one however any data i set and passed through when i called this container view automagically becomes available in the nested views (accessed in the normal way ie calling the variable name directly) hope you understand lol ben
[eluser]Carlos Mora[/eluser]
Ben, In your code you are passing just the $page name, but no other info to show into the view. The automagically part is the basic mechanism in CI to pass data to views. The magic happens in load->view(), where the array is converted into local vars, with a 'per function' scope, so loading nested views have the collateral effect of loosing the vars passed, ej. in your $this->load->view($page). A solution is, as posted, to introduce the global $data; into the container.php, so nested views can receive the vars passed in the original $data array. Please try changing your code into : Code: <body>;
[eluser]bengrice[/eluser]
no what im trying to say is that mines works. . . im looking at it now and it passes through and works fine no global no data var thats all cheers ben
[eluser]The Beginner[/eluser]
Hi all, I really appreciate this post, it give me much greater insite into how to complete my first major project in CI. The only thing I am wondering is, what is contained in "<?php $this->load->view('layout/meta');?>"? is this meta data files? What is it's purpose?
[eluser]khancute[/eluser]
[quote author="The Beginner" date="1253864836"]Hi all, I really appreciate this post, it give me much greater insite into how to complete my first major project in CI. The only thing I am wondering is, what is contained in "<?php $this->load->view('layout/meta');?>"? is this meta data files? What is it's purpose?[/quote] well if i'm not mistaken, the meta.php file is used to include all of your asset such as css files, javascript or ajax libraries.
[eluser]The Beginner[/eluser]
So does that mean that the css file I use for my menu that is currently included in my header_view could be loaded in that file instead, keeping all those things in one place? And if that is the case, obivously it would be available to header_view when it loaded? If I understand that correctly that is really cool. I still am having difficulty getting pea brain around that. Someone used the term AutoMagically, referring to CI, that is the way I feel about it right now.lol Hopefully someday soon I will get my head around it. Thanks, Del
[eluser]vecima[/eluser]
I took a somewhat different approach to this (headers and footers). in my controller (in my case my other controllers inherit from this one) i have a render method that the controllers call to set everything up. application/libraries/Base_controller.php (you can call it whatever you want obviously) Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); then other controllers can call _render like so: Code: //just put one view between the header and footer the only downside to this approach is that instead of having a "container" my header has: <html> <head> </head> <body> <some stuff /> and my footer has <some stuff /> </body> so you aren't getting all the tags neatly closed in one view, but instead of a container, head, and footer, i just have a header and footer.
[eluser]The Beginner[/eluser]
Hey guy's, I have tried both ways (with..: global $data, and with out and by the time I call $this->load->view('wpmenu') I get and error that 'memu' is not a valid var yet I set it in my Controller for wpmenu to = $data['menu']= $my_menu_data) also in my heaader file I am including a CSS file and tried using $base_url() and I get an error there that says base_url is an invalid function even though I am loading 'url' in autoload.php where $autoload['helper'] = array('snappy_source','url'); I am sure I am missing something, I just can't seam to figure out what it is. Any suggestions?
[eluser]khancute[/eluser]
[quote author="The Beginner" date="1254014508"]Hey guy's, I have tried both ways (with..: global $data, and with out and by the time I call $this->load->view('wpmenu') I get and error that 'memu' is not a valid var yet I set it in my Controller for wpmenu to = $data['menu']= $my_menu_data) also in my heaader file I am including a CSS file and tried using $base_url() and I get an error there that says base_url is an invalid function even though I am loading 'url' in autoload.php where $autoload['helper'] = array('snappy_source','url'); I am sure I am missing something, I just can't seam to figure out what it is. Any suggestions?[/quote] could you show your code, it kinda hard to see what might be the problem. i might have a guess but i'm not sure, better wait till you show your code. thanks |
Welcome Guest, Not a member yet? Register Sign In |