迅睿CMS框架是一款PHP8高性能·简单易用的CMS开源开发框架,基于MIT开源许可协议发布,免费且不限制商业使用,是免费开源的产品,以万端互联为设计理念,支持的微信公众号、小程序、APP客户端、移动端网站、PC网站等多终端式管理系统。
联系官方销售客服
1835022288
028-61286886
钩子里面引用类,该如何去引用,我要用save方法,如何去使用?$this不能直接用要引用类才行
$this模型类的话,全局是:\Phpcmf\Service::M()
$this模板类的话,全局是:\Phpcmf\Service::V()
$this控制器的话,全局是:\Phpcmf\Service::C()
\Phpcmf\Service::C()->model = 'work'; \Phpcmf\Service::C()->content_model = \Phpcmf\Service::M('Content', \Phpcmf\Service::C()->model); if (!empty($old['id'])){ \Phpcmf\Service::C()->content_model->save($old['id'],$data,$old); }else{ \Phpcmf\Service::C()->content_model->save(0,$data,0); }
<?php defined('SYSTEMPATH') || exit('No direct script access allowed'); ?> CRITICAL - 2020-06-11 08:50:46 --> Cannot re-assign $this # http://work.cc/admin.php?s=work&c=home&m=edit&id=11 # #0 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler() #1 {main} ERROR - 2020-06-11 08:51:33 --> 类文件:Fcms/Model/Work.php不存在
\Phpcmf\Service::C()->model = 'work'; \Phpcmf\Service::C()->content_model = \Phpcmf\Service::M('Content', \Phpcmf\Service::C()->model);
\Phpcmf\Service::C()->_module_init("work");
CRITICAL - 2020-06-11 09:32:17 --> Call to a member function save() on null # http://work.cc/admin.php?s=work&c=home&m=edit&id=11 # UPDATE `xxk_1_work` SET `url` = '/index.php?c=show&id=11' WHERE `id` = 11 #0 [internal function]: Phpcmf\Hooks::{closure}(Array, Array) #1 E:\phpstudy_pro\WWW\syywork\dayrui\System\Events\Events.php(188): call_user_func(Object(Closure), Array, Array) #2 E:\phpstudy_pro\WWW\syywork\dayrui\Fcms\Model\Content.php(349): CodeIgniter\Events\Events::trigger('module_content_...', Array, Array) #3 E:\phpstudy_pro\WWW\syywork\dayrui\Fcms\Core\Table.php(219): Phpcmf\Model\Content->save(11, Array, Array) #4 E:\phpstudy_pro\WWW\syywork\dayrui\Fcms\Control\Admin\Module.php(1192): Phpcmf\Table->_Save(11, Array, Array, Object(Closure), Object(Closure)) #5 E:\phpstudy_pro\WWW\syywork\dayrui\Fcms\Core\Table.php(338): Phpcmf\Admin\Module->_Save(11, Array, Array) #6 E:\phpstudy_pro\WWW\syywork\dayrui\Fcms\Control\Admin\Module.php(178): Phpcmf\Table->_Post(11, Array) #7 E:\phpstudy_pro\WWW\syywork\dayrui\App\Work\Controllers\Admin\Home.php(19): Phpcmf\Admin\Module->_Admin_Edit() #8 E:\phpstudy_pro\WWW\syywork\dayrui\System\CodeIgniter.php(914): Phpcmf\Controllers\Admin\Home->edit() #9 E:\phpstudy_pro\WWW\syywork\dayrui\System\CodeIgniter.php(400): CodeIgniter\CodeIgniter->runController(Object(Phpcmf\Controllers\Admin\Home)) #10 E:\phpstudy_pro\WWW\syywork\dayrui\System\CodeIgniter.php(308): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false) #11 E:\phpstudy_pro\WWW\syywork\dayrui\Fcms\Init.php(337): CodeIgniter\CodeIgniter->run() #12 E:\phpstudy_pro\WWW\syywork\index.php(47): require('E:\\phpstudy_pro...') #13 E:\phpstudy_pro\WWW\syywork\admin.php(9): require('E:\\phpstudy_pro...') #14 {main}
\Phpcmf\Hooks::on('module_content_after', function($data, $old) { if ($old[1]['state'] == 1){ $data[1]['updatetime'] = null; }else{ $data[1]['updatetime'] = strtotime(time()); } $t = \Phpcmf\Service::C()->_module_init("work"); if (!empty($old['id'])){ $t->save($old['id'],$data,$old); }else{ $t->save(0,$data,0); } });
$this->model = $catename[0]['mid']; $this->content_model = \Phpcmf\Service::M('Content', $this->model); $this->_module_init($this->model, SITE_ID, $this->module['share']); $this->content_model->save(0,$add,0)
\Phpcmf\Hooks::on('module_content_after', function($data, $old) { if ($old[1]['state'] == 1){ $data[1]['updatetime'] = null; }else{ $data[1]['updatetime'] = strtotime(time()); } \Phpcmf\Service::C()->_module_init("work"); if (!empty($old['id'])){ \Phpcmf\Service::C()->content_model->save($old['id'],$data,$old); }else{ \Phpcmf\Service::C()->content_model->save(0,$data,0); } });
\Phpcmf\Hooks::on('module_content_after', function($data, $old) { \Phpcmf\Service::M()->table_site(MOD_DIR)->update($data[1]['id'], [ "主表字段" => "新值", ]) });
\Phpcmf\Hooks::on('module_content_after', function($data, $old) { if ($data[1]['state'] == 1){ $date['time'] = ' '; }else{ $date['time'] = time(); } \Phpcmf\Service::M()->table(SITE_ID.'_work')->update($old['id'], ['updatetime' => $date['time']]); });
\Phpcmf\Hooks::on('module_content_after', function($data, $old) { if ($data[1]['state'] == 1){ $date['time'] = ' '; }else{ $date['time'] = time(); } \Phpcmf\Service::M()->table(SITE_ID.'_work')->update($data[1]['id'], ['updatetime' => $date['time']]); });
$this模型类的话,全局是:\Phpcmf\Service::M()
$this模板类的话,全局是:\Phpcmf\Service::V()
$this控制器的话,全局是:\Phpcmf\Service::C()
回复迅睿框架创始人
一直都是这样,发布出去
}