为什么app_model.php中的afterSave()总是在每次加载页面时触发?
class AppModel extends Model
{
public $cacheQueries = true;
var $actsAs = array('Containable');
function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
}
function afterSave($created) {
// Is used for better workflow when saving data
// Just for update
if(!$created) {
$_SESSION['redirect_update'] = true;
$_SESSION['redirect_to'] = $_SESSION['form_referer'];
debug('im always show on every page load!');
}
}
}
答案 0 :(得分:1)
刚刚检查了全新安装的Cake。 AppModel不会在每个页面加载时触发afterSave
。您的应用必须在您的某个控制器中调用某个型号上的save
(可能是您的AppController,因为每个页面都会调用它,或者检查您的beforeFilters)。