What exactly are you having problems with?
I don't know how far you've gotten but I would:
Setup the needed functions to generate the needed data for a directory in your model. Send this data to a view to display with a blade template.
I don't think there is much more than that to it (of course it sounds so easy in 2 sentences, though!).
Hi
I need to allow users to click on, for example, a directory name and have the contents returned to them - at the top level this is working (using directoryiterator), I run into problems however when visiting nested directories.
Forgive me, I'm learning as I go here, but can you create a model to represent directory information - I've only used models in the past to represent database content.
Thanks for the response..
Might be helpful if I provide more detail about the route setup and controller:
routes.php
Route::get('/{dir}, 'DirController@getDirContents');
DirController.php
public function getDirContents( $dir = NULL ) {
$toplevelpath = '/home/webs/sampleproject/webroot/public/resource';
if ( is_null($dir) ) {
$pathtoindex = $toplevelpath;
} else {
$pathtoindex = $toplevelpath.'/'.dir;
}
$files = new directoryIterator($pathtoindex);
return View::make('dirlisting')
->with('files', $files);
}
So the model would be something like this:
class Directory {
private $base_dir;
private $current_dir;
public function getListing() {
return new DirectoryIterator( $this->current_dir );
}
public function changeDirectory( $path ) {
//Check path is in $current_dir
//If it is, and permitted
$this->current_dir = $path;
//Return true on change or false if not
return $changed_dir;
}
Then your routes would be something like this:
Route::get( '/', 'DirController@getDirContents' );
Route::get( '/change/{dir}', 'DirController@getDirChange' );
Controller would have:
...
public function getDirContent() {
$files = Directory::getListing();
return View::make( 'dirlisting' )->with( 'files', $files );
}
public function getDirChange( $path ) {
$success = Directory::changeDirectory( $path );
//Get listing whether directory changed or not
$files = Directory::getListing();
return View::make( 'dirlisting' )->with( array( 'files' => $files, 'success' => $success );
}
Just getting back into Laravel, hope that generally works.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community