Stefan
Stefan

Reputation: 335

CakePHP doesn't load model

I'm new to cakePhp development. I've stuck on following problem: I've made few models, controllers and views - it works great. The problem is that after production, I have to made new table(Transactionaltemp table and corresponding model and controller ) in the db that logically is "connected" to other tables, but technically does not needs to - for ex. it holds temporary info on user_id, time, ip and similar. So, other tables doesn't need to be directly connected to that. The problem is when I try (in some other controller than transactionaltemps_controller):

$this->loadModel('Transactionaltemp');

I get error - the model is not found (it is true because the model is missing in the cache). Interesting enough transactionaltempls_controller is in the cache (in the cake_controllers_list file). I tried following stuff to resolve the problem:

  1. clear cache
  2. disable cache
  3. tried using uses={..} code in the controller that I would like to use mymodels_controller
  4. tried using init('Transactionaltemp')

with no success. Here is corresponding code: The model:

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

The controller:

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

 }
 ?>

I'll very grateful to any help!!!

Upvotes: 3

Views: 2842

Answers (3)

Pradhaban
Pradhaban

Reputation: 694

App:Import('Model','Transactionaltemp');
$this->Transactionaltemp= new Transactionaltemp;

I hope this may work

Upvotes: 1

user396716
user396716

Reputation:

Try

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

in your controller (or where you want).

Upvotes: 0

elboletaire
elboletaire

Reputation: 5367

If you are connecting to a table name with 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;
   }
}

Upvotes: 0

Related Questions