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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.