Reputation: 13025
I'm trying to implement a simple way to manage static pages in CakePhp, as described in this article.
The problem I'm facing is that App::import()
doesn't seem to import the required class in the routes.php file.
The code is the following:
App::import('Model','StaticPage');
$page = new StaticPage();
$slugs = $page->find('list', array(
'fields' => array('StaticPage.slug'),
'order' => 'StaticPage.slug DESC'
));
I'm getting the error: Fatal error: Class 'StaticPage' not found in ...
This class is present in the models folder (models/StaticPage.php).
I just started CakePhp a few weeks ago and I guess I'm missing a simple thing here...
I'm using CakePhp 1.3 and Php 5.2.42.
Upvotes: 0
Views: 1070
Reputation: 9964
I think the reason it doesn't work is because you don't follow CakePHP's naming conventions for file names: file names are lowercase and underscored. So renaming your file to static_page.php
should fix the problem.
Upvotes: 1
Reputation: 41256
Having taken a quick look at the article you reference, your snippet doesn't match up. You're importing the ClassRegistry
class (which doesn't need to be imported) and then trying to instantiate a StaticPage
. I'd recommend removing the AppImport
reference all together and using ClassRegistry
:
$page = ClassRegistry::init( 'StaticPage' );
You don't need the AppImport
line because ClassRegistry::init()
both loads the model and instantiates the object.
The other (potential) problem I see is that your model file name doesn't follow convention. It should be models/static_page.php
. Cake's inflection may not be handling the deviation from the norm.
Upvotes: 1
Reputation: 870
Like the error says: You are missing the Class StaticPage. Are you sure that you have this file? If you do, sure that it's in right place, has the right filename so the autoloader can find it?.
Upvotes: 0