[solved] simple read out in a loop.

ok guys. is it possible to realise something like this:

$dir = 'S:\software\externeSoftware\anwendungen\Netzwerk\aida32\report';

$files = scandir($dir);

echo '<select name="rechner" size="10" multiple>';

for ($j = 0; $j < count($files); $j++)


	if ($files[$j] != "." && $files[$j] != "..")


		echo '<option value="'.$j.'">'.$files[$j].'</option>';



echo '</select>';

in mvc with yii?

i just get the content of a folder and show it in a select box while rading it out in a loop.

plz guys need ur help. i can’t find out on my own the right combination between model view and controll.

have a look at this:


you just need to prepare the data array


i now got this:

$dir = 'S:\software\externeSoftware\anwendungen\Netzwerk\aida32\report';

$files = scandir($dir);

echo CHtml::dropDownList('rechner', 'auswahl', CHtml::listData($files, 'value', 'text'));

but the drop down is empty.

i used to prepare the datalist correctly. but how? sry for such dump questions.

tried now to read out the array with value() but still got problems with it.

aren’t there maybe any examples to the methods and functions?

scandir() function returns an array of strings, so you don’t need to use CHtml.listData() function since it takes an array of models (objects).

got it:

$dir = 'S:\software\externeSoftware\anwendungen\Netzwerk\aida32\report';

$files = scandir($dir);

$list = array_slice($files, 2);

echo CHtml::dropDownList('rechner', 'auswahl', $list);

but this isn’t mvc conform.can somebody hel me to mkae this mvc conform?

i’m doing it all in the view. but this isn’t right.

MVC structure…

MODEL - here you have the data ($dir="…") and a method to get the list of files (scandir,array_slice)

CONTROLLER - an action that will create a new model, call the method to get the list of fiels and pass that list to a view (render)

VIEW - the CHtml::dropDownList

ok i tried on my own. but i got still a few problems.

my model looks like this:

class UploadForm extends CFormModel


	public $list;


	public function getList()


		$dir = 'S:\software\externeSoftware\anwendungen\Netzwerk\aida32\report';

		$files = scandir($dir);

		$this->list = array_slice($files, 2);



my SiteController looks like this:

public function actionUpload()


		$form = new UploadForm();

		$list = $form->getList();




an my view like this:

$this->pageTitle = Yii::app()->name.' - Upload';

$this->breadcrumbs = array('Backend','Upload');

echo CHtml::form();

echo CHtml::dropDownList('rechner', 'auswahl', $list);

echo '<br />';

echo CHtml::submitButton('Upload');

echo CHtml::endForm();

and this is my error:

Invalid argument supplied for foreach()

although i wanted to know how to use the CHtml::errorSummary. Why do i get an fatal error when i put $form in it?

in getList() you need to return a value… like return $this->list

ok thx!

so my first yii application was born. and it is in mvc structure.

i’m happy :)