c_pattle Posted February 5, 2011 Share Posted February 5, 2011 I have just start using PHP classes and was wondering how you continue an instance of a class in another file. For example I have a folder called "includes" where I includes files that I send data to when I perform ajax request. However how do I continue an instance of class in these files? Hope that makes sense. Thanks for any help. Quote Link to comment Share on other sites More sharing options...
sunfighter Posted February 5, 2011 Share Posted February 5, 2011 It is customary to use the include file as a repository of files that you will include in your html/php pages. Put your server side ajax file into something like a folder called ajax. If you want to use a class that you have extended place it in a file and include it in all pages that require it. Put that file in your include folder. Quote Link to comment Share on other sites More sharing options...
lazylodr Posted February 5, 2011 Share Posted February 5, 2011 You can use a registry pattern, google it. Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 5, 2011 Share Posted February 5, 2011 I have just start using PHP classes and was wondering how you continue an instance of a class in another file. For example I have a folder called "includes" where I includes files that I send data to when I perform ajax request. However how do I continue an instance of class in these files? Hope that makes sense. Thanks for any help. Could you try to restate your question another way. I don't understand what you're asking. In terms of organization, the best practice is to put your classes into seperate files named for the class. Using this convention makes it easy to use autoloading. You can look at the documentation for PEAR, Zend Framework or symfony for examples. One example would be if you had a class named "MyClass" you could name the script, MyClass.class.php. What the autoloader will allow you to do, is use the class in your script, and when configured, if it can not find a direct include() for that script, it can search for a file that will provide the source for the class. It's very easy to setup the autoloader to take the class name, and then attempt to include a file named "MyClass.class.php". You can read more about this feature: http://php.net/manual/en/language.oop5.autoload.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.