Hello, I need some help.
The thing is, I need to be able to call functions (methods) delete and edit from template.
I have made a new Dataobject called 'LOTD' (still being tested):
<?php
class LOTD extends DataObject implements PermissionProvider{
static $db = array(
'LName' => 'Text',
'LOTD' => 'Text'
);
function providePermissions() {
return array(
"IMAOVLASTI" => "Unos, brisanje i editiranje LOTD",
"ADDLOTD" => array(
'name' => _t($this->class . '.ADDLOTD', ' Korisnik moze dodati LOTD'),
'category' => _t($this->class . '.ADDLOTD_CATEGORY', 'Ovlasti za LOTD'),
'help' => _t($this->class . 'ADDLOTD_HELP', 'Korisnik moze dodati Link Of The Day'),
'sort' => 1
)
);
}
function canAddLOTD($member = null){
if (($member == null)||($member == 0)) return false;
return (Permission::checkMember($member, 'ADDLOTD'));
}
function deleteLOTD($SQL_id) {
$lotd = DataObject::get_one('LOTD', "LName=$SQL_id",false,"");
$lotd->delete();
Director::redirectBack();
return null;
}
}
The function deleteLOTD (in this form) doesn't work... ignore most of the other things inside Dataobject LOTD, since they are under development. The idea is to have functions deleteLOTD and editLOTD inside 'LOTD' so I can use them with a push of a button from LOTDPage.ss template. This is part of LOTDPage.ss
<div id="newLOTDForm">
<% if canAddLOTD %>
<h2>Unos novog LOTD-a</h2>
$NewLOTDForm
<% end_if %>
<ul>
<% control getLOTDs %>
<li>
<a href="$LOTD">$LName</a>
</br>
<a href="$deleteLOTD('$LName')">Brisanje</a>
</li>
<% end_control %>
</ul>
</div>
the <a href="$deleteLOTD($LName)"> ... </a> doesn't work, else I wouldn't be asking how to do this.
getLOTDs function is inside LOTDPage.php and it looks like this:
function getLOTDs(){
return DataObject::get('LOTD');
}
also there is a form to enter new LOTD in database and for display that looks like this:
function NewLOTDForm() {
// Create fields
$fields = new FieldSet(
new TextField('LName'),
new TextField('LOTD')
);
// Create actions
$actions = new FieldSet(
new FormAction('addNewLOTD', 'Unesi')
);
$validator = new RequiredFields('LName', 'LOTD');
return new Form($this, 'NewLOTDForm', $fields, $actions, $validator);
}
function addNewLOTD($data, $form){
$submission = new LOTD();
$form->saveInto($submission);
$submission->write();
Director::redirectBack();
}
OK, so the idea is that when you click on "Brisanje" on the page that displays LOTDs (LOTD is actually Link Of The Day) it should call function deleteLOTD and delete it from database so it stops being displayed on the page and at the same time stops existing in LOTD table in database. Also if there is a kind heart out there that would like to help me with edit function aswell as with delete uinction