I have a diirectory containing textfiles,I normaly use DirectoryIterator class avaialble in php to iterate the directory and get filenames .I’ve got trouble trying it with CI. I’m completely new to CI ,so please bear with me :).
I’ve got something like this in my default controller named myblog (i wrote the function just after the index function).
<?php
public function diriterate()
{
$this->load->helper('directory');
$mapi=directory_map('./myfolder/');
$this->load->view('index.php',$mapi);
}
?>
and i’m trying something like this in my view
<?php
foreach($mapi as $key)
{
echo $key;
}
?>
Am i doing it plain wrong here ? .
(1) If my understanding is correct i can run it like mysitename/class/function (in my case localhost/myblog/diriterate) (2) My directory is inside the rootfolder (rootfolder/myfolder) so there is no need of baseurl or something ?.
Should i do this simply in the view using DirectoryIterator class or just create another controller for iteration,I’m really confused , any help is welcome .Thanks in advance.
Follow the MVC convention.
Model models/folder_model.php
For the directory map, it’ll look in the root directory of your application, meaning path that includes
index.php. Note that1will cause it to be non-recursive and only on that top-level path.Controller controllers/folder.php
View views/folder.php
This then would be viewable at
http://localhost/index.php/folder.