later to see the changes.
- edit files in the folder hello.php Edit Controllers Add Method.
Com_helloworld/Controllers/hello.php
function edit()
{
JRequest:setVar('view', 'hello');
parent::display();
}
- Modify the files in the folder hello.php Models.
com_helloworld/models/hello.php
public function getItem()
{
$pk = JRequest::getVar('cid');
if(is_array($pk)) {
$pk = $pk[0];
}
if($pk == '') {
return false;
}
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')
->from('#__helloworld_hello')
->where($db->quoteName('id').'='.$db->quote($pk));
$db->setQuery($query);
$db->query();
return $db->loadObject(); // ส่งค่าออกไปในรูปของ Object
}
protected function loadFormData()
{
$data = $this->getItem();
return $data;
}
function save($data)
{
$db = JFactory::getDbo();
$obj = (object) $data;
try {
if($obj->id) {
$db->updateObject('#__helloworld_hello', $obj, 'id');
} else {
$db->insertObject('#__helloworld_hello', $obj, 'id');
}
} catch (RuntimeException $exc) {
$this->setError($exc->getMessage());
return false;
}
return true;
}
- Modify the files in the folder hello.xml models / forms to id is hidden.
com_helloworld/models/forms/hello.xml
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="hello_form">
<field
name="id"
type="hidden"
/>
<field
name="name"
type="text"
class="inputbox"
label="Name"
required="true"
/>
<field
name="detail"
type="textarea"
class="inputbox"
label="Detail"
required="true"
rows="5"
/>
</fieldset>
</form>