Trying to understand an example in general topics |
In the general topics section on views it gives this example:
Let’s try it with your controller file. Open it add this code: Code: <?php Now open your view file and change the text to variables that correspond to the array keys in your data: Code: <html> I'm confused how the view file can access the variable $title without accessing the array that it is in. I would expect it to be something like Code: <html> Are all of the array elements converted into stand alone variables? Thank you.
The array $data is extracted by the loader class (library) and each array element is accessible as individual variables inside the view.
The original array ($data) is NOT passed, so it cannot be referenced in your view code. User Guide (3.0) REFERENCE: file:///home/twp/Dev/CI_3.0/user_guide/libraries/loader.html#class-reference Scroll down to the view method definition.
CI 3.1 Kubuntu 19.04 Apache 5.x Mysql 5.x PHP 5.x PHP 7.x
Remember: Obfuscation is a bad thing. Clarity is desirable over Brevity every time.
If you want a better understanding, the read the PHP documentation on the extract function. That function is called when views are "loaded".
|
Welcome Guest, Not a member yet? Register Sign In |