Jump to content

Fatal error: Class 'Sname_Router' not found in ...


ballhogjoni

Recommended Posts

This is so weird ... the class does exist.

In my index.php I am calling this line of code and this is the line that is throwing the error:

$router = new Sname_Router();

 

I am using a custom __autoload method and I am defining that function in index.php. Here it is

function __autoload($class_name) {
  require_once APPLICATION_PATH . '/../libraries/Sname/Autoloader.php';
  //Check to see if the class is in the app directory
  $loaded = Sname_Autoloader::loadClass($class_name,
                  array(APPLICATION_PATH . "/controllers/",
                      APPLICATION_PATH . "/models/",
                      APPLICATION_PATH . "/helpers/"));

  //Check to see if the class is in the libraries
  if (!$loaded)
    $loaded = Sname_Autoloader::loadClass($class_name, APPLICATION_PATH . '/../libraries/');

  //Check to see if the class is in active record
  if (!$loaded) {
    require_once APPLICATION_PATH . '/../libraries/activerecord/ActiveRecord.php';
    activerecord_autoload($class_name);
  }
  
  //Check to see if the class is in the include path
  if (!$loaded) {
    Sname_Autoloader::loadClass($class_name,
                    explode(PATH_SEPARATOR, get_include_path()));
  }
}

 

App directory structure

sname-git

- app

-- controllers

-- models

-- helpers

-- views

-libraries

--Sname

---Router.php

--activerecord

 

The Sname_Router class is located here /Users/myname/dev/git/sname-git/libraries/Sname/Router.php. I have checked to make sure that this is the correct location.

 

This is the first few lines of my Router.php

<?php

class Sname_Router {
...

 

What's going on? Any help would be much appreciated!

ok fixed it ... i hate trying to figure out the problem for hours and then writing up a post and then fixing the problem a minute later.

 

In my Sname_Autoloader::loadClass method I had the following code

if (!file_exists($file))
      return false;

 

I didn't realize file_exists was returning null so the method was always returning false. I changed that code to

if (file_exists($file) === null)
      return false;

 

and it works perfect!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.