IAmBob IAmBob - 2 months ago 11x
PHP Question

Trying to get list of views in folder in Codeigniter

I'm using Codeigniter, and all I'm trying to do is to get a list of all the views in a particular folder within the "views" folder.

Here's my code, inside of my controller:

$this->data['sections'] = array_diff( scandir('/application/views/portfolio/embeds/work/'), array('.', '..') );

And here is the error message I'm getting:

Message: scandir(/application/views/portfolio/embeds/work/): failed to open dir: No such file or directory

Filename: controllers/Work.php

Line Number: 54

Am I just forgetting something? Or is there maybe a way to set a relative path from the location of my controller? Because using the path "../views/portfolio/embeds/work/" doesn't seem to work either.


You need to add in the base path of your installation. Currently you are asking scandir to read the directory /application on your web server, when you most likely want /var/www/example.com/application

Try this:

 scandir(FCPATH . 'application/views/portfolio/embeds/work')