Newbie: Fatal error: Using $this when not in object context - URI Helper. |
[eluser]MEM[/eluser]
When the CI User Guide states: Quote:Note: This class is initialized automatically by the system so there is no need to do it manually. What does this mean? It means that we don't need to create an instance of a class? I was trying to use the following on my View: Code: if($this->uri->segment(3)==$arrMenu[i][$strChildKey]['id_cat']) I'm getting an error: Quote:Using $this when not in object context in /home/akasite/private/application/views/v_categoria.php on line 111 What's the issue? Márcio
[eluser]MEM[/eluser]
I believe this due the fact that we are trying to access $this inside a function (on our view). But why can't we? Márcio
[eluser]GSV Sleeper Service[/eluser]
because vars within functions are not global, unless you use the 'global' keyword. eg Code: $foo = 'donkey';
[eluser]MEM[/eluser]
Thanks. In fact CI allows us to do this by it's own methods right? http://ellislab.com/codeigniter/user-gui...passinguri So, I guess I have to forget about passing this on a view, and try to re-structure the all thing to be CI accordingly and use the controller instead. I have a big day in front of me... Thanks for lesson. Márcio
[eluser]cahva[/eluser]
If you want to use CI resources inside a function, just use the reference as GSV Sleeper Service mentioned. Code: function foo()
[eluser]MEM[/eluser]
Thanks Cahva. Hoping that I'm now doing something badly structured, I'm using it.
[eluser]BrianDHall[/eluser]
"You can always change it later" - one of my oft-repeated phrases Typically its best to load an array with the data you want your view to access, pass in the data to the view when you load it, and that makes things cleaner all the way around...but it's not mandatory, no one will slap you with a ruler for doing it. ...well, they might, but you'll live.
[eluser]MEM[/eluser]
Lol. Yes... it's a late lol. But now I need to build a menu, however, the menu subitems should appear, only when a specific uri is in place. The menu is build on a view, since I will only use one controller for that menu generation. However, even if I put this menu generation in a helper, I was still unable to use $this->uri right? So... I guess my ruler punishment will be a guarantee. Regards, Márcio |
Welcome Guest, Not a member yet? Register Sign In |