Cannot find the parsed data within a custom PHP function in views layout page |
|||
|---|---|---|---|
| Date: | 05/04/2008 | Severity: | Trivial |
| Status: | Bogus | Reporter: | joneslee |
| Version: | 1.6.0 | ||
| Keywords: | Libraries, Input and Security Class | ||
Description
The variable that is parsed from the controller to the layout page cannot be seen from a custom PHP function written within the layout page.
Here is the bug reproduction step:
In my controller:
$in = 1; //just an example
$data[‘in’] = $in;
In my view page, I wrote an custom PHP function:
<?php
function view() { echo ($in); }
?>
<html>
<body>
<?php view() ?>
</body>
</html>
Expected Result
Shows value 1 on the layout page
Actual Result
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: in
Comment on Bug Report
| Posted by: Derek Jones on 4 May 2008 8:59pm | |
|
|
Greetings, I do not see a forum thread associated with this bug report, and it looks like it may not be a bug. Have you first read the bug reporting guidelines and used the Bug Report Forum to get help confirming that this is a bug before reporting? Thanks! |
| Posted by: joneslee on 4 May 2008 9:25pm | |
|
|
Theorectically, it’s not wise to write a function within a layout page. However it should work if forced to. Can you please check if CI allow global variable can be referenced within a local function within the layout page? |
| Posted by: Derek Jones on 4 May 2008 9:42pm | |
|
|
View files variables are not scoped globally, so local functions in view files cannot access them. This is not an oversight, it is design. Scoping view variables globally could have many ill effects. If you need to use functions in your view files, create or modify a helper for them, do not define the functions in your view files. |
