Welcome Guest, Not a member yet? Register   Sign In
HELP! regarding variable scope in a library I created
#6

[eluser]danmontgomery[/eluser]
[quote author="steveh" date="1303798642"]my understanding of "$this->load->library('llib');" is that it would need to be done in each controller/view. I'd done the autoload to ensure the Llib was available without needing specific loading per controller/view. Am I right in thinking I can autoload it? and that your example requires loading per controller/view?[/quote]

You can, generally speaking you only want to autoload what you're using on every page, or close to it, otherwise it's wasting resources. If you don't autoload, you would have to explicitly load it per controller (or, per method, however), when you needed it.

[quote author="steveh" date="1303798642"]Also, in your example, what is the magic of referring to $this->myArray[...] as I'd have thought that myArray is already scoped local to Llib? or am I expecting too much here? or is '$this->" just a very explicit way of referring to something scoped in the embodying class? (is $this explicitly documented somewhere?) arrrgh![/quote]

$this indicates a member of the current class. You are expecting too much Wink Class or not, unless otherwise specified, variables are local to their current function.

[quote author="steveh" date="1303798642"](and also as I understand it, I need to do some other scoping stuff in my Llib to access CI libraries, per: "$CI =& get_instance();" ... hence my thinking there is various other scoping magic that I can't discern from generic documentation.)[/quote]

get_instance() returns the CI superobject, which is the Controller object. This is used when you need to access controller members from outside the scope of the controller.

[quote author="steveh" date="1303798642"]I should be declaring "var $myArray = array();" outside the class then have a "global $myArray" inside any of the class methods that utilise it?[/quote]

No... These are two different variables.


Messages In This Thread
HELP! regarding variable scope in a library I created - by El Forum - 04-25-2011, 07:28 AM
HELP! regarding variable scope in a library I created - by El Forum - 04-25-2011, 07:38 AM
HELP! regarding variable scope in a library I created - by El Forum - 04-25-2011, 10:04 AM
HELP! regarding variable scope in a library I created - by El Forum - 04-25-2011, 07:17 PM
HELP! regarding variable scope in a library I created - by El Forum - 04-25-2011, 08:47 PM
HELP! regarding variable scope in a library I created - by El Forum - 04-26-2011, 04:21 AM
HELP! regarding variable scope in a library I created - by El Forum - 04-26-2011, 06:05 AM
HELP! regarding variable scope in a library I created - by El Forum - 04-26-2011, 07:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB