Basically I want to make an extension that loads json files from a directory, loops through them and displays names and thumb-urls after a user has logged in. I don't understand where I should code this, I tried making an extension with the extension builder and work from there but I am lost. My show function in the MediaListController:
public function showAction(\Plaspack\PlaspackJson2media\Domain\Model\MediaList $mediaList)
{
$currentUser = $GLOBALS['TSFE']->fe_user->user['uname'];
$filepath = "json/mediaData_";
$filepath .= $currentUser;
$filepath .= ".json";
$result = file_get_contents ($filepath);
$json = json_decode($result,true);
print_r($json);
$mediaItems = $json[1];
foreach ($mediaItems as $key => $mediaItem){
echo $mediaItem["name"] . ", " . $mediaItem["url"]. "," . $mediaItem["thumbUrl"] ."<br>";
}
$this->view->assign('mediaList', $mediaList);
}
sounds like it is doable.
don't forget caching:
by default caching is done for user-groups, not on a per user base.
You should exclude your plugin/JSON-File from general caching and might do a caching by your own using the user-id as cache-tag.
you are on the right way.
consider: no echo
or print_r
in any TYPO3 functions!
because TYPO3 always stores the output in a string-variable which gets enhanced and enhanced until the string is shown in the end. Because of this every echo
will start the output and any configuration for the head will be to no avail.
have a look at the methods created by the extension builder: which method does a return $stringvar
? which method stores the result in a variable (like $this->view->assign()
)?
in your example you do echos
but does not assign anything from the data you just fetched.
what about a $this->view->assign('mediaList', $mediaItems);
to assign your current list to the fluid variable mediaList
?
additional thoughts:
don't use the field username
(uname
?) to distinguish users, use uid
, usernames could be changed, users could be deleted and a new user could select the deleted name.
why do you choose JSON-files? in your extension you could enhance the database fe_users table for a list of filelinks.
last: where is your caching? at least disable std caching, better: enter user specific cache tags