Cakephp3 - plugin class Table not loading

I am making a blog plugin with cakephp3. When I call url / blog / edit / 3 everything is fine, the form inputs are filled.

I have a class \ Blog \ Model \ Table \ ArticlesTable (file location: ROOT / plugins / blog / src / Model / Table / ArticlesTable.php)

Here's the class:

<?php
namespace Blog\Model\Table;

use \Cake\ORM\Table;
use \Cake\Validation\Validator;

class ArticlesTable extends Table
{
  public function initialize(array $config)
  {
    //die('IN ArticlesTable::initialize');
    $this->table('articles');
    $this->primaryKey('id');
    $this->addBehavior('Timestamp');
  }

  public function validationDefault(Validator $validator)
  {
  ...
  }
}

      

In debugar I see the message:

Generated models

The following table objects used Cake \ ORM \ Table instead of the concrete class: Articles

  • I check namespace and file case
  • I am running the linker command dumpautoloader

But my class is not loaded

Does anyone have an idea about my problem?

thank

Phil

+3


source to share


2 answers


I solved the problem. You must specify the plugins namespace when loading the model:

$this->loadModel('Namespace.TableName');

      

In my example, I changed:



class BlogController extends AppController
{
  public function initialize()
  {
    parent::initialize();
    $this->loadModel('Articles');//<----- HERE
  }
...
}

      

to

class BlogController extends AppController
{
  public function initialize()
  {
    parent::initialize();
    $this->loadModel('Blog.Articles'); //<----- HERE
  }
...
}

      

+2


source


Create a class ArticlesTable

in a folder src/Model/Table

. The easiest way to do this is to use the bake command



bin/cake bake model Articles

      

0


source







All Articles