Jump to content

php classes


c_pattle

Recommended Posts

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.