EllisLab text mark
Advanced Search
     
View loading failure
Posted: 29 August 2007 05:59 AM   [ Ignore ]
Joined: 2006-11-11
59 posts

I’ve just found a strange behaviour trying to load a view while adding dynamic data to it.
It’s a peculiar case and i need it to be confirmed before i submit it to the Bug Tracker.
My controller:

class MyController extends Controller
    {
    
        
function MyController()
        
{
            parent
::Controller();
        
}
    
        
function index()
        
{
            $data 
= array(
                
'title' => 'My Title',
                
'path' => 'My Title',
                
'heading' => 'My Heading',
                
'message' => 'My Message'
            
);
            
            
$this->load->view('myview'$data);
        
}
    
    } 

If in the passed array there is a key named “path” the view is not loaded at all
throwing this warning:

A PHP Error was encountered

Severity
Warning

Message
CI_Loader::include(My Title[function.CI-Loader-include]failed to open streamNo such file or directory

Filename
libraries/Loader.php

Line Number
652 

a quick check reveals that $data[‘path’] is used in libraries/Loader.php line 652 instead of the correct path.
Removing the $data[‘path’] key will fix the problem.

Is this a bug? Can you reproduce it?

—————————

Environement:
PHP Version 5.2.1
Apache 2.2.3

 
Posted: 29 August 2007 08:31 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-08-28
19 posts

Hi, maybe it’s small offtopic,
but if you use PHP v. 5.2.1 why u write constructor in PHP4 style?

 Signature 

Sex, drugs and PHP

 
Posted: 29 August 2007 08:37 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-07-24
82 posts

To make it compatible with PHP4?

 
Posted: 29 August 2007 09:24 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2006-11-11
59 posts

Instead of going off-topic, did you try and reproduce
the behaviour/bug?

 
Posted: 29 August 2007 09:32 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

do you have a myview.php file?

ok that was not the question, you can skip my question.

I tried to reproduce it and i got an error in the Loader class on line 639, a variable $path is used there.

 
Posted: 29 August 2007 09:56 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2006-11-11
59 posts
xwero - 29 August 2007 01:32 PM

I tried to reproduce it and i got an error in the Loader class on line 639, a variable $path is used there.

if you do a “var_dump($path)” you get “My Title” instead of the path/to/the/myview, don’t you?

 
Posted: 29 August 2007 10:18 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

Yes the $path value in the loader class was the value from the array. I used different values but with the same path key as you.

 
Posted: 29 August 2007 10:37 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2006-11-11
59 posts

It looks like a bug.
I will post it to the bugtracker.

 
Posted: 29 August 2007 11:04 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2006-06-23
370 posts

I’ve notified the person in charge of maintaining CI.

 Signature 

Mac OS X 10.8, Apache 2.x, NGiNX, PHP 5.4.x, CodeIgniter 1.7.2/2.1.3

 
Posted: 03 September 2007 06:37 PM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-11
103 posts

As I mentioned in this topic there are some reserved words in views.

Check the loader class and you’ll notice that there are some assignments to the $data array.

The following are reserved variable names:
view
vars
path
return

and they should be documented

 Signature 

Security Code Review

 
Posted: 03 September 2007 06:44 PM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2006-06-23
370 posts

I think they should be abstracted a bit more, such as prepending them with an underscore.

 Signature 

Mac OS X 10.8, Apache 2.x, NGiNX, PHP 5.4.x, CodeIgniter 1.7.2/2.1.3

 
Posted: 04 September 2007 06:46 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

I agree with coolfactor, path as a variable name has a legitimate use.

 
Posted: 04 September 2007 10:04 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-11
103 posts

All of them are of legitimate use for that matter.

I also agree with CF, an underscore (or even two) would be helpful to avoid collisions.
Some documentation on the matter would be good too

 Signature 

Security Code Review

 
Posted: 30 September 2007 01:49 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2007-03-16
1 posts

Hello. I’m a brazilian guy. Sorry for my bad english.

I discover CI two weeks ago and started a proejct. Yesterday I lost a afternoon because this problem.

Please, talk about this issue at User Guide. It’s simple and it will help lots of other people.

Thanks.

PS: CI rocks!