Tachi
Tachi

Reputation: 2202

Table objects used Cake\ORM\Table instead of a concrete class: How to fix?

I have this warning in my CakePHP logs:

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

Jobs

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 another/better way to access my db and read data from it? I'm using latest version of CakePHP. It's my first time using it, so I would like to know if there is a better way to do this MySQL interaction.

Upvotes: 4

Views: 2862

Answers (1)

Wes King
Wes King

Reputation: 627

Inside of src/Model/Table/, define a class named JobsTable.php:

<?php

namespace App\Model\Table;

use Cake\ORM\Table;

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

This should build your Table object from TableRegistry::get() with this class rather than the delegated Cake class.

You can learn more about building Table objects in CakePHP 3.x here:

CakePHP 3.x Table Objects

Upvotes: 6

Related Questions