3

I have StatsController.php with

class StatsController extends AppController {
    public function edit($id = null) {
        var_dump($this->Stat);
    }
}

I have StatModel.php with

class Stat extends AppModel {
    public $useTable = 'tips';
    // ....
}

When I try to save my data, my initial error is:

Missing Database Table | Error: Table stats for model Stat was not found in datasource default.

What am I doing wrong, thanks.

Here is the var_dump:

object(AppModel)[26]
  public 'useDbConfig' => string 'default' (length=7)
  public 'useTable' => string 'stats' (length=5)
  public 'id' => null
  public 'data' => 
    array (size=0)
      empty
  public 'schemaName' => null
  public 'table' => string 'stats' (length=5)
  public 'primaryKey' => string 'id' (length=2)
  protected '_schema' => null
  public 'validate' => 
    array (size=0)
      empty
  public 'validationErrors' => 
    array (size=0)
      empty
  public 'validationDomain' => null
  public 'plugin' => null
  public 'name' => string 'Stat' (length=4)
  public 'alias' => string 'Stat' (length=4)
  public 'tableToModel' => 
    array (size=1)
      'stats' => string 'Stat' (length=4)
  public 'cacheQueries' => boolean false
  public 'belongsTo' => 
    array (size=0)
      empty
  public 'hasOne' => 
    array (size=0)
      empty
  public 'hasMany' => 
    array (size=0)
      empty
  public 'hasAndBelongsToMany' => 
    array (size=0)
      empty
  public 'actsAs' => null
  public 'Behaviors' => 
    object(BehaviorCollection)[27]
      public 'modelName' => string 'Stat' (length=4)
      protected '_methods' => 
        array (size=0)
          empty
      protected '_mappedMethods' => 
        array (size=0)
          empty
      protected '_enabled' => 
        array (size=0)
          empty
      protected '_loaded' => 
        array (size=0)
          empty
      public 'defaultPriority' => int 10
  public 'whitelist' => 
    array (size=0)
      empty
  public 'cacheSources' => boolean true
  public 'findQueryType' => null
  public 'recursive' => int 1
  public 'order' => null
  public 'virtualFields' => 
    array (size=0)
      empty
  protected '_associationKeys' => 
    array (size=4)
      'belongsTo' => 
        array (size=6)
          0 => string 'className' (length=9)
          1 => string 'foreignKey' (length=10)
          2 => string 'conditions' (length=10)
          3 => string 'fields' (length=6)
          4 => string 'order' (length=5)
          5 => string 'counterCache' (length=12)
      'hasOne' => 
        array (size=6)
          0 => string 'className' (length=9)
          1 => string 'foreignKey' (length=10)
          2 => string 'conditions' (length=10)
          3 => string 'fields' (length=6)
          4 => string 'order' (length=5)
          5 => string 'dependent' (length=9)
      'hasMany' => 
        array (size=11)
          0 => string 'className' (length=9)
          1 => string 'foreignKey' (length=10)
          2 => string 'conditions' (length=10)
          3 => string 'fields' (length=6)
          4 => string 'order' (length=5)
          5 => string 'limit' (length=5)
          6 => string 'offset' (length=6)
          7 => string 'dependent' (length=9)
          8 => string 'exclusive' (length=9)
          9 => string 'finderQuery' (length=11)
          10 => string 'counterQuery' (length=12)
      'hasAndBelongsToMany' => 
        array (size=12)
          0 => string 'className' (length=9)
          1 => string 'joinTable' (length=9)
          2 => string 'with' (length=4)
          3 => string 'foreignKey' (length=10)
          4 => string 'associationForeignKey' (length=21)
          5 => string 'conditions' (length=10)
          6 => string 'fields' (length=6)
          7 => string 'order' (length=5)
          8 => string 'limit' (length=5)
          9 => string 'offset' (length=6)
          10 => string 'unique' (length=6)
          11 => string 'finderQuery' (length=11)
  protected '_associations' => 
    array (size=4)
      0 => string 'belongsTo' (length=9)
      1 => string 'hasOne' (length=6)
      2 => string 'hasMany' (length=7)
      3 => string 'hasAndBelongsToMany' (length=19)
  public '__backAssociation' => 
    array (size=0)
      empty
  public '__backInnerAssociation' => 
    array (size=0)
      empty
  public '__backOriginalAssociation' => 
    array (size=0)
      empty
  public '__backContainableAssociation' => 
    array (size=0)
      empty
  protected '_insertID' => null
  protected '_sourceConfigured' => boolean false
  public 'findMethods' => 
    array (size=6)
      'all' => boolean true
      'first' => boolean true
      'count' => boolean true
      'neighbors' => boolean true
      'list' => boolean true
      'threaded' => boolean true
  protected '_eventManager' => null
  protected '_validator' => null
zeflex
  • 1,487
  • 1
  • 14
  • 29
  • Please clarify: "it seems my model is not used". What are you actually trying in your 'edit' action, and what's not working? Also, what version of CakePHP are you in? And, why do you have "blablallalsaddasdasdasd" in your model. – Dave Jan 26 '14 at 19:19
  • @Dave at this time in my edit function I have only this code, fine. When I say 'my model is not used', I mean it seems to not be loaded because I have no php errors (in my code I put wrong stuff to generate an error). If everything was ok, it should break the code but it's not the case. I hope it's more clear. Version used is 2.4.4 – zeflex Jan 26 '14 at 19:21
  • Instead of asking a question to a problem that doesn't exist, try giving us the actual problem. Like... when I try to do a find() it's giving an error, or returning the wrong data...etc. You're basically saying "here's some code that has no problems - what's the problem?" Answer - nothing. – Dave Jan 26 '14 at 19:22
  • Well ok. My error is when I try to save my datas, my initial error is: Missing Database Table | Error: Table stats for model Stat was not found in datasource default. – zeflex Jan 26 '14 at 19:26

2 Answers2

4

I have StatModel.php with

Rename the file StatModel.php to Stat.php and ensure it's located in your Model folder. Model files are not appended with the word Model. I know, it's inconsistent with controllers but I didn't write Cake :)

When I call /stats/edit, it seems my model is not used, I didn't get any errors and also I am not able to change the table name (I want to use tips table)

CakePHP couldn't find the Stat.php file in your models folder so it automatically creates a fake model. Using the model name as a pattern it looks for a stats table.

Reactgular
  • 52,335
  • 19
  • 158
  • 208
-2

I guess the inflector can't resolve Stats to Stat properly. Don't use abbreviations, why not statistics? Why not TipsController at all if you deal with the tips table?

However, if you want to use that model try:

public $uses = array('Stat');

in your controller to explicitly set that model.

floriank
  • 25,546
  • 9
  • 42
  • 66