CakePHP does not load model

I am new to cakePhp development. I ran into the following problem: I made several models, controllers and views - it works great. The problem is that after production I have to create a new table ( Transactionaltemp and the corresponding model and controller) in db, which is logically "connected" to other tables, but technically not required - for ex. it contains temporary information about user_id, time, ip, etc. Thus, other tables need not be directly related to this. the problem is when I try (in a different controller than transactionaltemps_controller):

$this->loadModel('Transactionaltemp');

I get an error - the model was not found (this is true because it is missing ). Interestingly enough, it transactionaltempls_controlleris in the cache (in the file cake_controllers_list). I tried the following to solve the problem:

  • clear cache
  • disable cache
  • tried to use the uses={..}code in the controller that I would like to usemymodels_controller
  • tried to use init('Transactionaltemp')

without success. Here is the relevant code: Model:

<?php 
class Transactionaltemp extends AppModel
{
   var $name = 'Transactionaltemp';
   function beforeSave() {
    return true;
   }
}
?>

Controller:

<?php
 class TransactionaltempsController extends AppController
 {
    var $name = 'Transactionaltemps';
    var $scaffold;

 }
 ?>

I would be very grateful for any help !!!

+3
source share
3 answers
App:Import('Model','Transactionaltemp');
$this->Transactionaltemp= new Transactionaltemp;

I hope this might work

+1
source

If you connect to a table name with a different name than your model, you must specify the table name in it:

<?php 
class Transactionaltemp extends AppModel
{
   var $uses = 'Transactional';
   var $name = 'Transactionaltemp';
   function beforeSave() {
      return true;
   }
}
0
source

Try

App::Import('Model', 'YourModelName');

in your controller (or wherever you want).

0
source

Source: https://habr.com/ru/post/1791836/


All Articles