Reputation: 29
I'm busy upgrading a site for a client of mine. It's my first time working with CakePHP and I'm running into issues.
I created a table named banners
inside my database, and I made the following files:
Model/Banner.php
Controllers/BannersController.php
View/Banners/admin_index.ctp
It seems like my controller can't find the model. Whenever I try to load the page admin_index.ctp
I get the following message: Error: An Internal Error Has Occurred.
If i replace the contents of my public admin_index()
and make it echo text, it does work.
I also tried adding a form to my admin_index.ctp
by doing this
echo $this->Form->create('Banner');
This gives me another Error: An Internal Error Has Occurred.
I have set up my model, controller, view and database exactly the way the others for posts, pages, etc are set up and i just can't seem to get it to work. Does anyone have any idea on how to fix this?
Kind Regards,
Nick
<?php
class Banner extends AppModel {
}
?>
<?php
class BannersController extends AppController {
public $helpers = array('Html', 'Form');
public function admin_index(){
$banners = $this->Banner->find('all');
$this->set('banners', $banners);
}
?>
Stack Trace:
#0 /srv/nkuchiki/www/www.kuchiki.nl/app/webroot/index.php(111): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}
2015-04-10 17:29:43 Error: [MissingTableException] Table banners for model Banner was not found in datasource default.
Exception Attributes: array (
'table' => 'banners',
'class' => 'Banner',
'ds' => 'default',
)
Request URL: /admin/banners
Stack Trace:
#0 /srv/nkuchiki/www/www.kuchiki.nl/lib/Cake/Model/Model.php(3501): Model->setSource('banners')
#1 /srv/nkuchiki/www/www.kuchiki.nl/lib/Cake/Model/Model.php(2905): Model->getDataSource()
#2 /srv/nkuchiki/www/www.kuchiki.nl/lib/Cake/Model/Model.php(2877): Model->_readDataSource('all', Array)
#3 /srv/nkuchiki/www/www.kuchiki.nl/app/Controller/BannersController.php(7): Model->find('all')
#4 [internal function]: BannersController->admin_index()
#5 /srv/nkuchiki/www/www.kuchiki.nl/lib/Cake/Controller/Controller.php(490): ReflectionMethod->invokeArgs(Object(BannersController), Array)
#6 /srv/nkuchiki/www/www.kuchiki.nl/lib/Cake/Routing/Dispatcher.php(191): Controller->invokeAction(Object(CakeRequest))
#7 /srv/nkuchiki/www/www.kuchiki.nl/lib/Cake/Routing/Dispatcher.php(165): Dispatcher->_invoke(Object(BannersController), Object(CakeRequest))
#8 /srv/nkuchiki/www/www.kuchiki.nl/app/webroot/index.php(111): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#9 {main}
Upvotes: 0
Views: 653
Reputation: 29
Thanks for all the advice guys. Based on the extended error message i did some research on google and found some other threads on stackoverflow.
i removed the files in my tmp/cache/models, and tmp/cache/persistent and the problem was resolved :-).
It can be really difficult to find a problem when everything seems to be programmed right.
Upvotes: 2