Welcome Guest, Not a member yet? Register   Sign In
Unable to load the requested file error
#1

[eluser]pzntec[/eluser]
Hello!

I have the following code in my controller:
Code:
$this->parser->parse(base_url().'themes/default/index.php', $data);

And getting error:
Quote:Unable to load the requested file: http://localhost/PB_MVC/themes/default/index.php

However, when I type in the same url into the address bar, the page loads fine.

I can't for the life of me figure out what's going on.

Thanks in advance!

ADDITIONAL INFO:

Configs & Helpers are set as:
Code:
//Commented lines I've tried.
//$config['base_url'] = '';
//$config['base_url'] = 'http://localhost';
//$config['base_url'] = 'http://localhost/';
//$config['base_url'] = 'http://localhost/PB_MVC';
$config['base_url'] = 'http://localhost/PB_MVC/';
$autoload['helper'] = array('url');

My folder structure is:
-PB_MVC
--application
--system
--themes
---default
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

Why are you accessing your view file via HTTP? It's extra server work for no extra gain.

You'd be better off doing it more like this:
Code:
$this->parser->parse('themes/default/index.php', $data);
#3

[eluser]pzntec[/eluser]
Thank you!

yeah I guess I left that in there when I was messing around trying to get it to work. I have removed it and still the same problem.
Quote:Unable to load the requested file: themes/default/index.php
#4

[eluser]TheFuzzy0ne[/eluser]
You need to ensure that your view is in the ./application/views directory. Let's assume you have this structure:
Code:
application
+-- views
|    +-- themes
|    |    +-- default
|    |    |    +-- index.php

You would need to use the parser like this:
Code:
// Ommit the file extension.
$this->parser->parse('themes/default/index', $data);

Hope this helps.
#5

[eluser]pzntec[/eluser]
@TheFuzzy0ne - Yes thank you that does work! May I have an explanation as to why it doesn't work outside the application directory?

I like to know 'why' something works as well as 'how'. Smile Thank you!
#6

[eluser]TheFuzzy0ne[/eluser]
You can always just read the code, and see for yourself exactly what the code is doing, then you can try to figure out why.

I don't know off-hand, but since we have a directory for controllers and directory for models, I guess it made sense to also have one for views (since this is an MVC framework). Since that's where you're expected to put you views, that's where CodeIgniter looks for them. Views are usually stored on the local filesystem, so there's no need to support URL file paths.

Also, views are include()d, and the output is buffered. As the file is loaded, it's parsed by the PHP parser, so variables and any other PHP code will be evaluated and executed too.

I suspect you assumed that it would just use file_get_contents() or fopen(), and thus allow you to use a URL as a filename, but since the file is include()d, and include() doesn't support URLs, the view loading method first checks to see if the file exists where it expects to find it before include()ing it.

If you did want to load external content, you can simply use file_get_contents($url) (which won't be parsed by the PHP parser), and then pass that into a view, but I doubt you'd ever need to do that.

Hope this helps.
#7

[eluser]pzntec[/eluser]
excellent thank you for your time.

Unfortunately I can't debug CI for I get 'Disallowed Key Characters'. Haven't had a chance to find a solution for that yet.




Theme © iAndrew 2016 - Forum software by © MyBB