Can not find cakephp model - php

I am having extreme issues trying to get cakephp to find a model. i been working on this project for 4 months now and created ton's of models but for some reason, cake can not find this model. This is how it is set up at minimum
app/controllers/arbitrations_controller.php
<?php
class ArbitrationsController extends AppController {
var $name = 'Arbitrations';
}
app/models/arbitration.php
<?php
class Arbitration extends AppModel {
var $name = 'Arbitration';
}
database name: arbitrations
Error Message
Controller::paginate() - can't find model Arbitration in controller
ArbitrationsController [CORE\cake\libs\controller\controller.php, line
1102]
I've tried clearing tmp/cache/models and tmp/cache/persistent

I got it to work. I just deleted my arbitrations_controller.php file and recreated and it worked. Must be some type of glitch or something. I think it may have had something to do with even going about deleting the tmp files and recreating the files again.
Dont know what it was, but it wasted 3 hours of my life.

I just set this up using CakePHP v1.3.x and it worked out of the box using scaffolding. A couple of things you can try:
Double check the spelling on everything. Arbitration can be easily
misspelled.
Add the var $uses = array('Arbitration') to the top of the
controller and see if that changes anything.
Double check the model spellings in the controller
$this->Arbitration->recursive = -1;
If all of those things are set and working as expected it should work. Another thing to try is to load it in a clean app to see if it works in a stand alone environment.

Related

Phalcon pdo excpetion model first

I have problem with phalcon framework namely with models methods...
As you know models has included methods find() and findFirst()
I have generated model with phalcon-dev tools and now I am trying to do Model::find on it but I am getting an exception but dont know why...
There is some more informations (e.g stacktrace) :
http://exception.mateuszmarzecki.pl/
You can try change methods in model file
public static function find($parameters = array())
{
return self::find($parameters);
}
Does not look like your passing it the right parms.
SELECT FROM `nacionality`
Notice that your not selecting any fields from the database, and that is why your getting the Exception.
So... after some time of debugging I've found the problem...
For the next generation... if you don't want to lose a week as I did. Just read carefully your application config.
Problems occurs because I missed table and column annotations as well.
In my application config I have something like:
$metaData->setStrategy(new \Engine\Db\Model\Annotations\Metadata());
so Phalcon was looking for annotations in my model files, more info about this you can find there:
https://forum.phalconphp.com/discussion/1933/column-types-for-model-annotations
Happy New Year

Yii2 Model initialization AND session handeling

Here's a pickle :)
In the old Yii you could instantiate models anywhere in protected. Regardless of the module you were in. Then the Yii team decided to go and mess everything up :) and decided to change the structure and code and now, I'm a bit lost...
1. HOW DO YOU INSTANTIATE MODELS? (anywhere in the project)
Old fashion way was $model = new Model(); where model could be in a totally different module and it would still work. How do we do this now? when I try to do it, it says: Class 'app\modules\somemodule\controllers\Model' not found which is funny because I want a model and it searches in controllers...
2. SESSIONS IN YII
Old fashion way was
Yii::app()->session['var'] = 'value';
echo Yii::app()->session['var']; // Prints "value"
How are they done now?
L.E: Found my answer to the second question :D and sessions are handled about the same: Yii::$app->session['var'] = 'value'; the difference being the $... It's all about the $ :)
Thank you!
Ares.
Funny how no one showed interest in my question...
Anyways, nothing changed about it. If you need new fresh instance it's just "new Post()". If you need to get AR model with data it's "Post::find->where(...)->one()"
BUT you have to:
Either import class from another namespace with use:
use app\modules\someModule\models\Post;
// ...
$post = new Post();
or use fully qualified class name:
$post = new \app\modules\someModule\models\Post();
Hope this helps others as well as it did me :D

Laravel 4 does not extend Eloquent class

I have a Product.php file in app/models folder. Here is the content of the file:
class Product extends Eloquent{
protected $table = 'productinfo';
}
However, when I tried to run $product = Product::all();, Laravel say Call to undefined method Product::all(). It seems like Eloquent class is not extended.
I don't see anything I do wrong here. Why does it not working? Could it be any other configuration in Laravel which I mess up?
--update--
After renaming the Product.php file, it is now no longer showing error message. But the problem is, it does not properly return the result from database. Instead, the returned result is {"incrementing":true,"timestamps":true,"exists":true}. Not the result from database.
So, I tried to run a clean new Laravel project from composer and the only files that I modified is the config/database.php file to set it work with MySQL database, route.php file, and the models/Products.php file. When I browse it on browser, again it shows the same result: {"incrementing":true,"timestamps":true,"exists":true}, not database result.
I really don't know what causing it. I have tried with it in one my experiment Laravel project folder which has lots of junk in it, and it works perfectly fine here.
Do you know why it doesn't work? How to solve it?
Thank you.

CodeIgniter + Active Record Spark save function is not working

This is thoroughly confusing me. I am trying to gather very basic statistics on my site, namely how many hits I am getting per day.
In a superclass that every controller inherits I have this code.
// log every hit
if(STATISTICS == 'all')
{
$stat = new Statistic();
$stat->ip = $this->_get_ip_address();
$stat->save();
}
I am loading the spark before this block. I do have a table setup named Statistics. I have the Model file created named Statistic with a classname of Statistic. Everything works well except when I try to save.
I can print out the $stat object and it returns an Active Record Object with everything set up properly. But for some reason when I try to call $stat->save(); every page just returns an Internal Server Error.
I have not added a new Model to my site in a while so I may have forgotten something, but this is really bugging me.
Anyone have any ideas?
More Information:
My Statistic Model:
class Statistic extends ActiveRecord\Model {
}
It seems that nothing was wrong with my code at all. It all works beautifully.
Protip: Don't forget to set your id to auto increment in the database.

Disable Cakephp's Auto Model "feature"

In cake 1.2 there is a feature that allows the developer to no have to create models, but rather have cake do the detective work at run time and create the model for you. This process happens each time and is neat but in my case very hazardous. I read about this somewhere and now I'm experiencing the bad side of this.
I've created a plugin with all the files and everything appeared to be just great. That is until i tried to use some of the model's associations and functions. Then cake claims that this model i've created doesn't exist. I've narrowed it down to cake using this auto model feature instead of throwing and error! So i have no idea what's wrong!
Does anybody know how to disable this auto model feature? It's a good thought, but I can't seem to find where i've gone wrong with my plugin and an error would be very helpful!
There's always the possibility to actually create the model file and set var $useTable = false.
If this is not what you're asking for and the model and its associations actually do exist, but Cake seems to be unable to find them, you'll have to triple check the names of all models and their class names in both the actual model definition and in the association definitions.
AFAIK you can't disable the auto modelling.
Cake 1.2
It's a hack and it's ugly cus you need to edit core cake files but this is how i do it:
\cake\libs\class_registry.php : line 127ish
if (App::import($type, $plugin . $class)) {
${$class} =& new $class($options);
} elseif ($type === 'Model') {
/* Print out whatever debug info we have then exit */
pr($objects);
die("unable to find class $type, $plugin$class");
/* We don't want to base this on the app model */
${$class} =& new AppModel($options);
}
Cake 2
Costa recommends changing $strict to true in the init function on line 95 of Cake\Utility\ClassRegistry.php
See Cake Api Docs for init
ClassRegistry.php - init function
Use
var $useTable = false;
in your model definition.
Delete all cached files (all files under app/tmp, keep the folders)
In most cases where models seem to be acting in unexpected ways, often they dont include changes you've made, it is because that cake is useing an old cached version of the model.
Uh...where do we start. First, as Alexander suggested, clear your app cache.
If you still get the same behaviour, there is probably something wrong with the class and/or file names.
Remember the rules, for controller:
* classname: BlastsController
* filename: blasts_controller.php
for model:
* classname: Blast
* filename: blast.php
Don't foget to handle the irregular inflections properly.

Categories