CodeIgniter Forums

Full Version: Model error (1.6.1)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I'm currently getting my feet wet with CodeIgniter, and I must say I like it. Scalable php framework. Very nice. I'm working my way through the user guide, and I seem to have stumbled on the models section. (Not very far I know,) I have:
class New_model extends Model
function New_model()
function get_something()
return("hello person!");

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">&lt;html xmlns="" xml:lang="en" lang="en"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;
<h1>&lt;?php echo $heading;?&gt;</h1>
<div id="content">
&lt;?php foreach($content as $item):?&gt;
<p>&lt;?php echo $item;?&gt;</p>
&lt;?php endforeach;?&gt;

class Blog extends Controller
function blogit()
$data['title']="CodeIgnitor Blog Model example";
$data['heading']="Model Example";
$data['content'] = array($this->Blogmodel->get_last(),"hello again");
$this->load->view('blogview', $data);
function sayit()
$data['title']="CodeIgnitor Blog Model test";
$data['heading']="Model Testing";
$data['content'] = array($this->New_model->get_something(),"hello again");
$this->load->view('blogview', $data);
function index()

$content = array( "First paragraph<br />Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"Second paragraph of stuff would go here if this actually worked. This is complex. lol.<br />");
/* $data = array( 'title' => 'CodeIgniter Blog'
'heading' => 'Welcome to my Blog!'
'content' => $content);
$data['title'] = "CodeIgnitor Blog";
$data['heading'] = "Blog Entry";
$data['content'] = $content;
$this->load->view('blogview', $data);
function comments()
echo 'Look at this!';
function about()
echo 'I\'m currently fixing this up. Check back later!';

All the files are in the right folders and such. The config.php file has the base_url as It's under /uncharted/cms on the server.
Now if I use MAMP (I'm running Mac OS 10.4.11 on PowerPC) I have the folder under ~/Sites/cms/. If I set up a server running at cms (so you can just type http://cms/index.php/blog in the browser) then everything works fine. cms/index.php/blog /blog/blogit /blog/sayit. Now if I am working on my server, I get the following:

An Error Was Encountered

Unable to locate the model you have specified: new_model

Now if I save the file as blogmodel.php (not capitalized) then it works, but not if I save it as Blogmodel.php. Also it has to be all non-caps inside the file (blogmodel extends Model) Any explanation? Sorry it's a long winded description.
You can checkout /blogit /sayit

El Forum

The file name must be lower case, certainly... But the class name must be capitalized...
Quote:Where Model_name is the name of your class. Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.

The file name will be a lower case version of your class name.

But the funny thing: are you naming your class New_model and the file blogmodel.php ? The class name must be equal to the file name (only capitalized =P).

El Forum

Thanks! I kinda figured that out. Wink