Table objects used Cake \ ORM \ Table instead of a specific class: how to fix it?

I have this warning in CakePHP logs:

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

Job

Here is my controller class:

<?php
namespace App\Controller;

use App\Controller\AppController;
use Cake\ORM\TableRegistry;

/**
 * Jobs Controller
 *
 * @property \App\Model\Table\JobsTable $Jobs
 */
class JobsController extends AppController
{
    public $name = 'Jobs';

    /**
     * Index method
     *
     * @return void
     */
    public function index()
    {
        //Set Query Options
        $options = array(
            'order' => array('Jobs.created' => 'desc'),
            'limit' => 1
        );

        //Get Jobs info
        $getjobs = TableRegistry::get('Jobs');
        $jobs = $getjobs->find('all',$options);
        $this->set('jobs',$jobs);
    }
}

Is there any other / better way to access my db and read data from it? I am using the latest version of CakePHP. This is my first time using it, so I would like to know if there is a better way for this interaction with MySQL.

+4
source share
1 answer

Inside src / Model / Table / define a class called JobsTable.php:

<?php

namespace App\Model\Table;

use Cake\ORM\Table;

class JobsTable extends Table
{
    // ... Jobs Table logic defined here
}

This should create a Table object from TableRegistry :: get () with this class, and not with the delegated Cake class.

You can read more about creating table objects in CakePHP 3.x in more detail:

CakePHP 3.x

+6

All Articles