3

I make a plugin Blog with cakephp3. When I call the url /blog/edit/3, all is good, the form inputs are filled.

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

Here 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 the debugar, I see the message :

Generated Models

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

  • I check namespace and the case of file
  • I run command composer dumpautoloader

But my class is not loaded

Some one has an idea about my problem ?

Thanks

Phil

4
  • I guess you shouldn't use use \Cake\ORM\Table; but use Cake\ORM\Table;. I mean, remove the first slash. I'll recommend you to use bake to generate the base code. Commented Apr 23, 2015 at 17:40
  • I remove Blog/src/Model/Entity/Article.php and Blog/Model/Entity/Article.php and run the command : bin\cake.bat bake model Articles -p Blog Files are created but the problem persists : The following Table objects used Cake\ORM\Table instead of a concrete class: Articles Commented Apr 24, 2015 at 6:41
  • Where and how is the specific table instance created? Commented Apr 24, 2015 at 13:06
  • in the folder /plugins/Blog/src/Model/Table/ and the filename is ArticlesTable.php Commented Apr 27, 2015 at 11:39

2 Answers 2

2

I resolved the problem. You need to specify the plugin namespace while 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
  }
...
}
Sign up to request clarification or add additional context in comments.

Comments

0

Create the ArticlesTable class in the src/Model/Table folder. The easiest way to do it is using the bake command

bin/cake bake model Articles

3 Comments

I run the command, files \plugins\Blog\src\Model\Table\ArticlesTable.php, \plugins\Blog\src\Model\Entity\Article.php are created but these files are not loaded. I'm on Windows is it the reason ?! is there a cache to clean ?
In My /config/bootstrap.php, I have Plugin::loadAll( 'Blog' => ['routes' => true, 'autoload' => true, ]); In the /composer.json "autoload": { "psr-4": { "App\\": "src", "Blog\\": "./plugins/Blog/src" } }, But the problem persits with the line $this->loadModel('Blog.Articles'); commented so the autload doesn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.