<?php
App::uses('Component', 'Controller');
class PersistentComponent extends Component
{
var $components = array('Session');
var $Controller = null;
function initialize(&$controller, $settings = array())
{
$this->Controller = & $controller;
}
function beforeRender(&$controller)
{
$persistentData = $this->Session->read('PersistentData');
if($persistentData)
{
foreach($persistentData as $key=>$value)
{
if(isset($value['errors']))
ClassRegistry::init($key)->validationErrors = $value['errors'];
if(isset($value['data']))
$controller->request->data[$key] = $value['data'];
$this->Session->delete('PersistentData.'. $key);
}
}
}
function beforeRedirect(&$controller, $url, $status=null, $exit=true)
{
foreach ($controller->uses as $modelName)
{
if(count($controller->$modelName->validationErrors)) {
$this->Session->write('PersistentData.' . $modelName . '.errors', $controller->$modelName->validationErrors);
}
if(isset($controller->request->data[$modelName]))
$this->Session->write('PersistentData.' . $modelName . '.data', $controller->request->data[$modelName]);
}
}
}
?>