![]() |
Default Layout - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Default Layout (/showthread.php?tid=18752) |
Default Layout - El Forum - 05-17-2009 [eluser]derekmichaeljohnson[/eluser] [quote author="Dam1an" date="1242597560"]If that doesn’t solve it, you’ll have to pass the data array in another array, and then pass the sub data array (the real data) into the second level view I hope that makes sense[/quote]It probably does, but I'm too new to CI to get it :-) Can you give me an example of how I can pass the data array from the index into an array and then load it into the second level view? Thanks man. Default Layout - El Forum - 05-17-2009 [eluser]Dam1an[/eluser] I just tested it using load->vars and it works Code: // index function Thats all there is too it Default Layout - El Forum - 05-17-2009 [eluser]derekmichaeljohnson[/eluser] But this: Code: $this->data['cal'] = $this->calendar->generate() So if the render method is being run post-controller, how do I grab the data array from the "Home" controller class (for example), collect it in the render method and pass it with the layout view, within which the controller-specific view ("home/home_view" in this example) is loaded? Haha it sounds pretty damn complicated for what you would think would be an easy task. Default Layout - El Forum - 05-17-2009 [eluser]Dam1an[/eluser] Because you've already declared the variable $data in MY_Controller So when you call $this->data, as it already exists in that classes (you home controllers) scope, it will use that So when your post controller executed, it goes to the MY_Controller, and all the data in in that data array ![]() Default Layout - El Forum - 06-08-2009 [eluser]mighty_falcon[/eluser] hey there, I was just attempting the same thing as laid out by your sample code but for some reason I am not able to load up any data using $this->data = array('whatever' => 'whatever) which is being set in the particular controller (in this case the home one). Any ideas? Default Layout - El Forum - 06-09-2009 [eluser]Dam1an[/eluser] Can you post some code so I can get a better idea of what you mean? The only things I could suggest off the top of my head is to make sure you decare the data variable in your class and then make it into an array Code: $data = array(); Not having that could cause some issues if you're running PHP4 I think (at least someone had that problem in the past and that was the cause) Default Layout - El Forum - 06-09-2009 [eluser]mighty_falcon[/eluser] [quote author="Dam1an" date="1244553275"]Can you post some code so I can get a better idea of what you mean? The only things I could suggest off the top of my head is to make sure you decare the data variable in your class and then make it into an array Code: $data = array(); Not having that could cause some issues if you're running PHP4 I think (at least someone had that problem in the past and that was the cause)[/quote] well my classes are exactly like the ones you posted in your example: MY_Controller Code: class MY_Controller extends Controller { the conroller file: Code: //helpers I cannot seem to be able to access any data i pass on to $this->data from the controller class...am i doing something wrong when extending MY_controller? Default Layout - El Forum - 06-09-2009 [eluser]mighty_falcon[/eluser] you know the strange thing is that if i do a print_r($this->data) on the application controllers (home in this case) it accesses the indices set in the MY_Controller constructor just fine. If i were to do print_r($this->data) in the render function i do not get any indices that i created in the application controller. Have you gotten this to work with the post_controller hook yourself? Default Layout - El Forum - 06-10-2009 [eluser]jedd[/eluser] Hmm .. a few things spring out there (though I'm having trouble identifying your intent in your MY_Controller) In your controller, do you extend MY_Controller, or just Controller? Why - in your controller - are you assigning: Code: $this->data = $popular; This will overwrite any extant data in $this->data. You would instead need to do something like this: Code: $this->data['popular'] = $popular; Most importantly I think is your render() method in your MY_Controller - I do not think it does what you think it will do. Read up in the [url="http://ellislab.com/codeigniter/user-guide/general/views.html"]CI manual on generating views[/url] - specifically the third parameter being set to TRUE - and then look at your render function again, and probably assign the output of that view generation to a variable, or just return it (I'd go for the former, and test for success/fail before returning anything - but I'm a cautious kind of guy). Default Layout - El Forum - 06-10-2009 [eluser]Dam1an[/eluser] Jedd seems to have picked up on the main points (as always) I would just like to say (disclaimer) this was never meant to be widely used code, it was just a 'hack' I posted to help a user... I've since moved to something more complex, and moved it into a seperate library. As Jedd mentioned, you're overwritting the data array, so you may expect to have a veriable $popular in the view, but instead get $0, $1, $2 etc (Is it even possible to have a variable start with a number?) As for the view issue, I was loading a master view which would load nested views in it, you seem to be loading is as a single view, so the top level view only has the arrays (such as data, views) not their contents as you expect |