Title: Joomla postSaveHook set jform
Tags: php;oop;joomla;joomla3.0;joomla-component
Question: Im busy with an image moving function so im overriding some controller functions, and unfortuantly i required the items id for the image name so i changed form save() to postSaveHook() as i was not able to get the item id in save() but now im facing another problem i cant set form data to the newly renamed image.
Here's the code:
public function postSaveHook($model, $validData){
$item = $model-&gt;getItem();
$id = $item-&gt;get('id');
$path = JPath75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0lean(JPATH_SITE. DS ."images". DS ."menu_slider". DS );
$input=JFactory75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0getApplication()-&gt;input;
$input-&gt;get('jform', NULL, NULL);
$src_image = $this-&gt;moveOriginal($path,$id);
$imageTest = $this-&gt;findImages($src_image);
if(!empty($imageTest)){
foreach($imageTest as $images){
$this-&gt;createImageSlices($images,$src_image,$path);
}
}else{
echo 'all images are there';
/*this part no longer works*/
$data = JRequest75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0getVar( 'jform', null, 'post', 'array' );
$data['image'] = 'images'.DS.'menu_slider'.DS.'original'.DS.$src_image;
$input-&gt;post-&gt;set('jform',$data);
return parent75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0postSaveHook($model, $validData);
is there anyway i can save the data from this? or if i revert back to save, how would i get the id?
Any Help Greatly Appreciated.

Here is the accepted answer: I tried different ways and the absolute safest way for me was to add the following code in the model
class DPCasesModelCase extends JModelAdmin {
public function save($data) {
new EventHandler(JDispatcher75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0getInstance(), $this);
return parent75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0save($data);
class EventHandler extends JEvent {
private $model = null;
public function __construct(&amp;$subject, $model) {
parent75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0__construct($subject);
$this-&gt;model = $model;
public function onContentChangeState($context, $pks, $value) {
if ($context != 'com_dpcases.case' &amp;&amp; $context != 'com_dpcases.form') {
return;
}
if (! is_array($pks)) {
$pks = array($pks);
}
foreach ( $pks as $pk ) {
$this-&gt;dowork($this-&gt;model-&gt;getItem($pk), 'edit');
}
public function onContentAfterSave($context, $object, $isNew) {
if ($context != 'com_dpcases.case' &amp;&amp; $context != 'com_dpcases.form') {
return;
}
$this-&gt;dowork($object, $isNew ? 'create' : 'edit');
private function dowork($object, $action) {
...


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:10/16/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><oop><joomla><joomla3.0><joomla-component>', 'Title': 'Joomla postSaveHook set jform', 'ViewCount': 1361, 'id': 19406351, 'user_AboutMe': None, 'user_AccountId': None, 'user_DisplayName': None, 'user_Reputation': None, 'user_Views': None, 'user_id': None}}