I've created a custom component in which my client can add and manage different accommodations. I would like to automatically create a folder (with name of Alias) inside '/images' whenever the client adds a new object (accommodation) to the component. I did find that I should be able to fire for example JFolder::create
on onContentAfterSave
, found a example of somebody using it to do the same in com_articles with use of a plugin, but somehow I cannot get it to work inside my custom component.
(To be complete: the issue here is that the mediamanager, when used in a subform like I do, does not show the option to create a folder. Hence I would like to add it this way).
Anyone any thoughts on this?
// code I have in edit.php of component
function onContentAfterSave(){
$foldername = $accommodation->alias;
// First we set up parameters
$searchpath = JUri::root() . '/images/accommodations' . $foldername;
// Joomla doesn't autoload JFile and JFolder
JLoader::register('JFile', JPATH_LIBRARIES . '/joomla/filesystem/file.php');
JLoader::register('JFolder', JPATH_LIBRARIES . '/joomla/filesystem/folder.php');
// Then we create the subfolders
if (!JFolder::create($searchpath . "/gallery"))
{
};
if (!JFolder::create($searchpath . "/slider"))
{
};
};