Welcome Guest, Not a member yet? Register   Sign In
CI is outputting the code from MY_model class and then saying it can't find it
#1

[eluser]php_princess[/eluser]
I used CodeIgniter on a remote server, for a live site, for several months. I'm now trying to get the site to run on my computer so I can use my computer as a testing server. So far I can't get it working.

When I go to the index page, I get the following output. Take note of the fatal error at the bottom.

Code:
<?

class MY_model extends CI_model {

public function __construct()
{
parent::__construct();
}

/*-------------------------------------
TRASH CAN
------------
Used whenever an admin deletes something. It takes what was deleted and puts it in a table called trash_can.
It will stay in trash_can for one week before a cron job deletes it.

$info will be an array

*/

protected function trash_can($info) //ingo is an array in the format column => value
{
if (!is_array($info)) return FALSE;

$col_string = '';
$val_string = '';

//make the strings that go in table name parenthesis and value parenthesis

$counter = 0;

foreach ($info as $column => $value)
{
  $col_string .= '`'.$column.'`';
  $val_string .= $this->db->escape($value);
  
  $counter++;
  
  //This puts a comma after the comma or value, unless it's the last comma/value.
  if ($counter != count($info))
  {
   $col_string .= ', ';
   $val_string .= ', ';
  }
}

//print "({$col_string}) VALUES ({$val_string})"; die;

$query = $this->db->query("INSERT INTO `trash_can` (".$col_string.") VALUES (".$val_string.")");

return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
}

protected function delete($id, $params) //params is an array
{

}

}
?&gt;<br />
<b>Fatal error</b>:  Class 'MY_Model' not found in <b>C:\xampp\htdocs\spice\core\Common.php</b> on line <b>174</b><br />
#2

[eluser]TheFuzzy0ne[/eluser]
Sorry, I don't understand. Is the model code being output as well?

It's pretty common to run into compatibility issues between *nix and Windows-based servers. However, these are normally to do with case-insensitivity. Since Windows is case-insensitive, it usually means that what works on Windows, doesn't work on Linux, not the other way round. So I'm not sure if this has anything to do with case-sensitivity.

I would suggest you look into virtualisation if you can. Then you can run a virtual machine that runs the same (or similar) OS to your production server. www.vagrantup.com is a good place to start, but there can be a steep learning curve, but it's well worth it.

It might work if you change:
Code:
class MY_model extends CI_model {

to:
Code:
class MY_Model extends CI_Model {

It may not fix the issue, but adhering to convention can certainly help fix these kinds of problems.
#3

[eluser]php_princess[/eluser]
Actually, when I load the page in the browser it shows me this:

Code:
value { if (!is_array($info)) return FALSE; $col_string = ''; $val_string = ''; //make the strings that go in table name parenthesis and value parenthesis  $counter = 0; foreach ($info as $column => $value) { $col_string .= '`'.$column.'`'; $val_string .= $this->db->escape($value); $counter++; //This puts a comma after the comma or value, unless it's the last comma/value. if ($counter != count($info)) { $col_string .= ', ';  $val_string .= ', '; } } //print "({$col_string}) VALUES ({$val_string})"; die; $query = $this->db->query("INSERT INTO `trash_can` (".$col_string.") VALUES (".$val_string.")"); return ($this->db->affected_rows() > 0) ? TRUE : FALSE;  } protected function delete($id, $params) //params is an array { } } ?&gt;
Fatal error: Class 'MY_Model' not found in C:\xampp\htdocs\spice\core\Common.php on line 174

but when I view I tell my browser to view the source, I get that code that I pasted in my first post. It starts with the code for My_Model and then shows the fatal error. OH! And it's saying MY_Model now because I changed that, like you asked me to.

And yes the remote server is Linux and yes my local computer is Windows.
#4

[eluser]TheFuzzy0ne[/eluser]
Please ensure you have error reporting set to report all errors. There may be other non-fatal errors responsible, which aren't being output.

In index.php:
Code:
&lt;?php

ini_set('display_errors', '1');
error_reporting(E_ALL);

/* ... */

Are you able to include the file manually?
Code:
include APPPATH . 'core/MY_Model' . EXT
#5

[eluser]TheFuzzy0ne[/eluser]
Sorry, I actually thought this was another post, and I'm trying to help with a problem you don't actually have, although enabling error reporting will most likely help.

I think that short tags aren't supported either by your version of PHP or your configuration. I think changing &lt;? to &lt;?php will sort your problem.

It's also recommended to omit the closing PHP tag to prevent output problems due to trailing whitespace. Instead, it's a good idea to put a comment at the end of the file, so you can be sure it hasn't been truncated.
Code:
// End of file MY_Model.php
// Location: ./application/core/MY_Model.php

#6

[eluser]php_princess[/eluser]
Wow, I didn't even notice it was &lt;? and not &lt;?php

I changed it to the right one and the error went away.

Now the site is loading (kind of) and I'm going to poke at it see if I can get it to load the rest of the way.




Theme © iAndrew 2016 - Forum software by © MyBB