Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8794621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:16:36+00:00 2026-06-13T23:16:36+00:00

So my project uses an MVC framework and I have a page with an

  • 0

So my project uses an MVC framework and I have a page with an Ajax script I run to get content from the server. When the PHP script is called in the Ajax script, I want to access the classes already in my library for use in the PHP script. To do this, I use what I call an ajaxBootstrap to call the appropriate function that then instantiates the objects needed for that specific Ajax script.

To load those classes from my library I have an autoload function in my ajaxBootstrap so I don’t need to use a bunch of require and include statements. My problem is those files aren’t being loaded due to a path issue with the autoload function. When I use a require statement with the same path, the classes load with no problems, its only when I try to load them using the autoload function that I get an 500 internal server error.

Here is my ajaxBootstrap file:

// This file routes Ajax requests made in JS files and instantiates a specific object to carry out the actions needed for that particular Ajax operation 

// Autoload any classes that are required
function autoLoad($classToLoad)
{
    if(file_exists('../library/' . $classToLoad . 'class.php')) // File in the library folder
    {
        require('../library/' . $classToLoad . '.class.php');
   }
    else if(file_exists('../../app/models/' . $classToLoad . 'class.php')) // File in the models folder
    {
        require('../../app/models/' . $classToLoad . '.class.php');
    }
}

spl_autoload_register('autoLoad');

// Determine which function to call based on the url that's listed in the Ajax request
switch($_GET['action'])
{
    case 'pageOne':
        pageOne();
        break;
    case 'pageTwo':
        pageTwo();
        break;
}

function pageOne()
{
    $test = new Test();
    $test->funcThatReturnStuff();
}

function pageTwo()
{
    $test2 = new Test2();
    $test2->funcThatReturnStuff();
}

Like I mentioned eariler, if I use a require statement such as:

require('../library/Test.class.php');
$test = new Test();
$test->funcThatReturnStuff();

The class loads and works just fine. But using the same path in the autoloader function throws an error. The really odd thing is if I put an else if statement in the autoloader that loads a class from the folder where my ajaxBootstrap is it also works fine too…

I know I could just use the require statements and be done with the problem but I want to be able to scale the project and not need to use loads of require statements in the future. BTW, I use ‘../’ to get from where my ajaxBootstrap file is to my other folders.

Also, to add to my previous post, I’ve tried replacing the ../ with absolute paths using define('ROOT', dirname(__FILE__) . '/') and also define('ROOT', $_SERVER['DOCUMENT_ROOT'] . '/path/to/folder/') neither of which worked and still gave me the internal server error in Firebug. In addition, I haven’t received any errors in my error log either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:16:37+00:00Added an answer on June 13, 2026 at 11:16 pm

    Nevermind… Even after staring at my code for the past few hours I somehow missed the missing period in two of my file paths. I hate coding sometimes… Thank you to anyone who took time to read this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MVC 3 project that uses Entity Framework. I can successfully update
I have a new MVC project which uses the entity framework. I'm spitting out
I have an ASP.NET MVC project that uses a SQL Server Compact database. I
Hi I have a Visual Studio solution and an ASP.NET MVC project that uses
I have an Asp.net MVC project that modestly uses jQuery scripts. My views also
I have an ASP.Net MVC project that uses EF. I develop this application at
I'm working on MVC project and i using jQuery in view page to get
I have an ASP.NET MVC 3 (using Entity Framework 4.2) application that uses transactions
just a quick question about the mvc JqueryUI framework, i have a _layout.cshtml page
I have a project that uses MVC 3 and Entity Franework. The site works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.