I have a view (actually a few views) where I need to include some file uploading capabilities.
in my view I have the following sections
-
press release
-
technical documents
-
daily results
each one of those needs to have an instance of the file uploader linked to it so that I can send the content to the appropriate directory structure. (i.e. documents/press, documents/tech and documents/results/day)
I made this script work
http://blog.mbischof.de/mit-yii-eine-datei-hochladen
is there a way to call the upload script from another view?
right now the upload scripts sits in this directory
protected/views/site/upload.php
and the view I want to call it from is in
protected/views/event/results.php
I tried using renderPartial from within results.php but it didn’t work. it did however work when I copied this code (this was in SiteController) right inside the view as a test only
public function actionUpload() {
$form = new UploadForm;
if (isset($_POST['UploadForm'])) {
if ($form->validate()) {
$form->file = CUploadedFile::getInstance($form, 'file');
$file= dirname(Yii::app()->request->scriptFile) . DIRECTORY_SEPARATOR . $form->file->name;
$form->file->saveAs($file);
}
}
$this->render('upload', array('form'=>$form));
}
I must be close since I can get it work but i’m sure there’s a fancier way of doing this than me copying the contents of that actionUpload function everytime I want to use it
would creating a widget be better? if so, how would you go about creating one based on the code I have from the blog linked above?
Pabs