Reassign page variables values

edited May 2015 in Modules
basicaly i have a custom template field"whatsnew" with two field values as "link" and "weight". So they are stored as page_variables. Now i want to rearrange weight base on another values "wn_articles" array order. everything is fine. The only problem is that after save, i am not able to save the updated value to the field. So i think that may because i did not assign the modified value to the $post array, so the page variables are not saved. I reassign the modified values to $this->normalzed_save_data, but not working, what can i do in this case.

// class extended from page_model
function on_after_update($v)
{
$values=$this->normalized_save_data;

$id=$v['id'];

if(!empty($values['wn_articles'])){
$total=count($values['wn_articles'])*2+1;

$new_order=array();
foreach($values['wn_articles'] as $k=>$v){
$new_order[$v]=$total-$k*2;
}

foreach($values['whatsnew'] as $a){
if(isset($a['link']))
$a['weight']=$new_order[$a['link']];
}
$this->normalized_save_data=$values;
}
return $v;
}

Comments

  • edited May 2015
    on_Before_save is also failed
  • edited 3:09AM
    please help
  • edited 3:09AM
    Strange... I swore I responded to this earlier. $this->normalzed_save_data is only a holder of the data that is posted and changing it won't change saved values. I would recommend creating a layout class that implements the method "process_saved_values". This method gets passed the values that will be processed for saving before it is handed off to the model to be saved. More on creating a layout as from a custom class can be found here:
    http://docs.getfuelcms.com/general/layouts#layouts_custom_classes
  • edited 3:09AM
    so no way we using any hook? how about make a class extend from page_variables then do after_update? but the problem is that, how to link the page_model to this custom page_variables class?
  • edited 3:09AM
    The "process_saved_values" or the "post_process_saved_values" are essentially a "hooks" but at the layout level. You can load in the models into the hook like so on your Layout class:
    public function post_process_saved_values($values){ $CI =& get_instance(); $CI->load->module_model(FUEL_FOLDER, 'fuel_pages_model'); $CI->load->module_model(FUEL_FOLDER, 'fuel_pagevariables_model'); //... your code here }
    Does that make sense?
Sign In or Register to comment.