Cakephp3 : using another model in a controller

前端 未结 1 1750
孤独总比滥情好
孤独总比滥情好 2020-12-18 15:09

I started an app with CakePHP3 and i need to record some users\'s actions. So, I have migrated my log structure, I have baked my controller & model and now, I try to get

相关标签:
1条回答
  • 2020-12-18 16:05

    This way

    use Cake\ORM\TableRegistry;
    
    $logs = TableRegistry::get('LogsTable');
    $logs->save($log);
    

    more info

    EDIT since 3.6 you should use

    use Cake\ORM\TableLocator
    
    $articles = TableRegistry::getTableLocator()->get('Articles', [
        'className' => 'App\Custom\ArticlesTable',
        'table' => 'my_articles',
        'connection' => $connectionObject,
        'schema' => $schemaObject,
        'entityClass' => 'Custom\EntityClass',
        'eventManager' => $eventManager,
        'behaviors' => $behaviorRegistry
    ]);
    

    more info here

    0 讨论(0)
提交回复
热议问题