[Flow] Resource Publishing
Andre Hohmann
mail at andre-hohmann.net
Sat May 2 17:36:11 CEST 2015
Hallo,
I have a few questions regarding Ressource Mangement.
1.)
Like described in
http://docs.typo3.org/flow/TYPO3FlowDocumentation/TheDefinitiveGuide/PartIII/ResourceManagement.html
I want to import an existing file. Therefore I created a Model file
"Download.php":
<?php
namespace ITOOPAtcDomainModel;
class Download {
/**
* @var string
*/
protected $title;
/**
* @var TYPO3FlowResourceResource
*/
protected $originalResource;
/**
* @param string $title
* @return void
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param TYPO3FlowResourceResource $originalResource
* @return void
*/
public function setOriginalResource(TYPO3FlowResourceResource
$originalResource) {
$this->originalResource = $originalResource;
}
/**
* @return TYPO3FlowResourceResource
*/
public function getOriginalResource() {
return $this->originalResource;
}
}
If I execute on a shell "./flow doctrine:update" I get the error "The
mapping of field 'originalResource' is invalid: The option 'OneToOne' is
required." If I add "@ORMManyToOne", and execute "./flow
doctrine:update" again, I get the error "SQLSTATE[HY000]: General error:
1005 Can't create table
'atc.#sql-586_1978' (errno: 150)". If I drop the property "protected
$originalResource;" completely, I can execute "./flow doctrine:update"
without an error. Does anybody know, why?
2.)
I created a "DownloadRepository.php", too and the following
"DownloadController.php":
class DownloadController extends ActionController {
/**
* @FlowInject
* @var itoopatcDomainRepositoryDownloadRepository
*/
protected $downloadRepository;
/**
* @FlowInject
* @var TYPO3FlowResourceResourceManager
*/
protected $resourceManager;
/**
* @return void
* index action
*/
public function indexAction() {
}
/**
* Imports an image
*
*
* @return void
*/
public function downloadAction() {
// path, where the original file is stored
$csvPath =
'/var/www/apps/flow/Packages/Application/ITOOP.Atc/Resources/Private/Export/test.csv';
// import original file into TYPO3 Flow's persistent resources storage
and
// return a new Resource object which refers to the newly imported file
$newResource = $this->resourceManager->importResource($csvPath);
// create new object "download" which refers to the newly imported file
$newDownload = new itoopatcDomainModelDownload();
// attach the ressource to the new object "download"
$newDownload->setOriginalResource($newResource);
// get datetime
$currentdatetime = new DateTime();
// format datetime to string
$cdt = $currentdatetime->format('YmdHis');
// set datetime as title for new download object
$newDownload->setTitle($cdt);
// add new object "download" to downloadRepository
$this->downloadRepository->add($newDownload);
$this->redirect('index');
}
}
If I execute the downloadAction, everything works, so a new object with
an originalressource as hash an datetime as title is stored in the
database. (I know, I should completely forget sql tables and only think
of objects, but if I search for errors, sometimes I think it's easier
for me to prove in sql, what is stored).
But now I don't understand, how to get access to the object/file! My aim
is to to provide the file stored unter
"/var/www/apps/flow/Packages/Application/ITOOP.Atc/Resources/Private/Export/test.csv"
as download for the application users, when they execute a special
action. When I try to make the file/object available in fluid by...
"<a src="{f:uri.resource(resource: download.resource)}">Download</a>"
...that doesn't work. Does anybody know, how to get access to the
object/file in a actionContoller?
--
Mit freundlichen Grüssen
Andre Hohmann
---------------------------------------------------------------------------------------------
http://www.andre-hohmann.net
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren und die unbefugte Weitergabe dieser E-Mail sind nicht gestattet.
More information about the Flow
mailing list