Field variable problem |
[eluser]iainco[/eluser]
Code: <?php if(!defined('BASEPATH')) exit('No direct script access allowed.'); I'm having trouble accessing my field array variable article after the constructor and index methods are called. When a user accesses http://localhost/article/article-title-here everything works fine, the _fetch helper method is used to get information about the article from the database. This information is what I want to still be available and accessible by all other methods. But after the view is loaded, and I try the rating function... which calls the rate method, I get an error that $this->article['ID'] is null, in fact, $this->article is also null. So basically I'm not sure why it's not working, is it just tha I can't expect the article field array variable to still be available for when another method of the controller is accessed? Please get back to me if you need more information. Thanks
[eluser]iainco[/eluser]
Yeh, the index method is working fine, and is loading the view correctly and all information is shown how I want it. But it's when I come back to call a separate method in controller (rate), by submitting a form on the page that is loaded, it is unable to access the article array.
[eluser]uptime[/eluser]
[quote author="Chels87" date="1227655432"]Yeh, the index method is working fine, and is loading the view correctly and all information is shown how I want it. But it's when I come back to call a separate method in controller (rate), by submitting a form on the page that is loaded, it is unable to access the article array.[/quote] Add this at the beginning of rate(): Code: var_dump( $this->_fetch() ); What does it return?
[eluser]Colin Williams[/eluser]
I must assume your rating form submits to the wrong URI.
[eluser]iainco[/eluser]
It's okay, the problem is that the constructor for the class is called again when the rate method is called. I can get it working as I need it, just requires some extra code. Thanks guys
[eluser]uptime[/eluser]
Yeah, the constructor is always called, make sure you have the title in your uri->segment(2) and it's a done deal. Good luck! |
Welcome Guest, Not a member yet? Register Sign In |