Jump to content

Search the Community

Showing results for tags 'autoloading'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 2 results

  1. Im trying to implement the PSR-0 autoloader found here : Autoloader I have simply copied and pasted the code as it is shown in the link so should work out of the box. Here is my file structure for my App: I believe i have set up the file structure correctly. App being the vendor, and then the folders below all being namespaces e.g. Frontend, Base, index will all be namespaces and subnamespaces. The autoloader classes specifies this code in order the initiate the autoloader: $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); $classLoader->register(); And in my app i have used this: $classLoader = new SplClassLoader('App', SITE_ROOT); $classLoader->register(); The reason i have only put App as the namespace for the classLoader function is because i need to autoload all classes under the App folder. Here is the initiation of my router class which i believe should be autoloaded so i don't have to include it: $route = new router(); $route->setDefaultController(DEFAULT_CONTROLLER); $route->setDefaultMethod(DEFAULT_METHOD); $route->do_route(); $controller = $route->getController(); $method = $route->getMethod(); $arguments = $route->getArgs(); Is this correct? it doesnt seem to be loading any of the classes, not even the router class which is in the same directory as the autoloader? Im getting pretty confused about what should be parsed to the SPLClassLoader function shown above for a namespace. Any help in this area will be much appreciated Thanks
  2. I have recently started using OOP for my old procedural code and I'm getting the hang of it. The problem I have is with autoloading my class files. I have this code on each of my pages I'm redoing. require("php/classes/dbConstants.php"); function __autoload($className) { $extensions = array(".php", ".class.php", ".inc"); $paths = explode(PATH_SEPARATOR, get_include_path()); $className = str_replace("_" , DIRECTORY_SEPARATOR, $className); foreach ($paths as $path) { $filename = $path . DIRECTORY_SEPARATOR . $className; foreach ($extensions as $ext) { if (is_readable($filename . $ext)) { require_once $filename . $ext; break; } } } } try { $forum = new Database(DBHOST, DBUSER, DBPASS, DBNAME); } catch (Exception $e) { echo $e->getMessage(), "\n"; } but i'm getting this error message The file with the autoloader is in the root and the database class is in a folder called php and in a subfolder called classes. I need to adjust the path of where it's looking for my classes but no idea how Can anyone please help?
×
×
  • 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.