Support the ongoing development of Laravel.io →
Requests Input
Last updated 1 year ago.
0

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!).

Last updated 1 year ago.
0

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..

Last updated 1 year ago.
0

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);
}
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

aireyrf aireyrf Joined 16 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.