I'm making an add-on to enable users to delete entries outside of the admin-interface. I think I have everything up working, except for the small problem of converting an url (/myentries/1337-23) into a path (/_content/1-myentries/2015-01-28-1337-23). Shouldn't resolve do the trick? Or is there other functions that I can use?
Trigger
{{ entries:listing folder="myentries" }}
<form action="" method="post">
<input type="hidden" name="myfile[delete]" value="{{ url }}"/>
<button type="submit" class="button--delete">Delete entry</button>
</form>
{{ /entries:listing }}
Add on
<?php
class Hooks_myfile extends Hooks {
public function request__post()
{
if (array_get($_POST, 'myfile:delete')) {
$filename = array_get($_POST, 'myfile:delete');
$filename = PATH::resolve($filename);
$currenturl = URL::getCurrent();
FILE::delete($filname);
URL::redirect($filename);
}
}
}
?>