Welcome Guest, Not a member yet? Register   Sign In
Model error (1.6.1)
#1

[eluser]benaroia[/eluser]
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:
New_model.php
<?php
class New_model extends Model
{
function New_model()
{
parent::Model();
}
function get_something()
{
return("hello person!");
}
}
?>

blogview.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&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;
&lt;/head&gt;
&lt;body&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;
</div>
&lt;/body&gt;
&lt;/html&gt;

blog.php:
&lt;?php
class Blog extends Controller
{
function blogit()
{
$data['title']="CodeIgnitor Blog Model example";
$data['heading']="Model Example";
$this->load->model('Blogmodel');
$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";
$this->load->model('New_model');
$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!';
}
}
?&gt;

All the files are in the right folders and such. The config.php file has the base_url as http://www.unchartedmess.com/. 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 http://www.unchartedmess.com/cms/index.php/blog /blogit /sayit
Thanks!
#2

[eluser]Seppo[/eluser]
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).
#3

[eluser]benaroia[/eluser]
Thanks! I kinda figured that out. Wink




Theme © iAndrew 2016 - Forum software by © MyBB