为什么 app_model.php 中的 afterSave() 总是触发?
为什么 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!');
}
}
}
Why is afterSave() inside app_model.php always triggering on every page load?
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!');
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚检查了新安装的 Cake。 AppModel 不会在每次页面加载时触发
afterSave
。您的应用必须在某个控制器(可能是您的 AppController,因为每个页面都会调用它,或者检查您的 beforeFilters)中的某个模型上调用save
。Just checked a fresh install of Cake. AppModel does not fire
afterSave
on every page load. Your app must be calling asave
on some model in one of your controllers (possibly your AppController since it is called for every page, or check your beforeFilters).