3
votes

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!!!

3
What is the name of the file in which you have defined your model?Leo
Can you access the model from its own controller (Transactionaltemps)?Leo
Yes, I can access the model from its own controller. Name of the file in which I have defined my model is same as model's class name - transactionaltemp.phpStefan
It would be helpful if you posted some code to show some context around how you are using loadModel(). The syntax for uses, BTW, is var $uses=array('ModelOne','ModelTwo'); not as you have written above. If you do use $uses, the host model must be first in the array.Leo

3 Answers

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

I hope this may work

0
votes

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;
   }
}
0
votes

Try

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

in your controller (or where you want).