Using Elfinder extension in Yii

2019-09-15 00:12发布

问题:

I need to use a file manager in pop up which comes on a button click. I am using Yii extension elfinder. I am finding it hard to understand the way of using it. I downloaded the code from bitbucket, put it inside my application in the folder extension. I try to test it using new controller, named it elfcontroller and put the following code (got from the website)

class ElfinderController extends CController
{
public function actions()
{
    return array(
        'connector' => array(
            'class' => 'ext.elFinder.ElFinderConnectorAction',
            'settings' => array(
                'root' => Yii::getPathOfAlias('webroot') . '/uploads/',
                'URL' => Yii::app()->baseUrl . '/uploads/',
                'rootAlias' => 'Home',
                'mimeDetect' => 'none'
            )
        ),
    );
}
}

and i created one more function for rendering the index page(i want the file manager to be in this page)

in the view i wrote the following code

$model = new xxxmodel();
$this->widget('ext.elFinder.ElFinderWidget', array(
      'model' => $model,
      'attribute' => 'serverFile',
      'connectorRoute' => 'admin/elfinder/connector',
      )
  );

and i included a div for containing it

But i am getting the following error

Alias "ext.elFinder.ElFinderWidget" is invalid. Make sure it points to an existing PHP file and the file is readable.

i tried to include alias in config/main.php

I know i am messing some where with the folder structure

here is the path i am using the extension C:\xampp\htdocs\project\protected\extensions\ext.elfinder

I returned empty after google searches, can any one please explain me how to use this extension to place the code exactly where it is needed to be?

回答1:

In general the extensions folder already has the ext alias, so you don't need to set an alias for it.

Then the extension itself should be placed in the extensions folder, somewhat like : project/extensions/extension-name/ . In your case it should be: project\extensions\elFinder , and keep the rest of your code same, i.e continue referring to extension like:

ext.elFinder.ElFinderWidget