CakePHP: loading models without model files

I have tables that are created on the fly, and I would like to access it through the model. Since these tables are dynamically created, I do not have model .php files for them. Tables are created in accordance with the Cake Naming Convention. I tried using loadModel () to load them, but Cake still complains that the tables are missing.

Is there a solution for this?

Thank.

+3
source share
2 answers

Starting on this post using CakePHP 2.1.2

In the controller add App::uses('AppModel', 'Model');. Then create an instance of the model

    $RemoteHeader = new AppModel(array(
                'table' => 'SOP10100',
                'ds' => 'external',
                'name' => 'RemoteHeader',
                'alias' => 'InvoiceHeader',
                'primaryKey' => 'id',
                'hasMany' => array(
                    'InvoiceDetail' => array(
                        'foreignKey' => 'SOPNUMBE',
                        'counterCache' => false
                ))));

then select the data with any model parameters you need:

    $data = $RemoteHeader->find('all', array(
            'fields' => array(
            'SOPNUMBE',
            'CUSTNAME',
            'DUEDATE',
            'DOCDATE',
            'DOCAMNT',
            'SUBTOTAL')));
+4
source

Create /app/models/dynamic.phpwith class

class Dynamic extends AppModel {
    var $name = 'Dynamic'
    var $useTable = null;
}

$this->Dynamic->useTable = 'newly-created-table';

, , .

0

All Articles