php for 71 php for

Most object oriented languages support modern technologies targeted programs, and PHP is no exception. While many development projects simple network, no need to object approach focusing on large projects often do. When I am developing a web application, and the choice of technique is to use programs, usually the choice of object-centered approach of some sort, although I was able to use all capabilities object-oriented I had available to PHP.

In this article, instead of describing its objectives and what classes will look at a simple example which should show how you can use for art object-oriented programs when you develop network applications.

Consider the following simple HTML code.

index.htm

[HTML]
[a]
[/ Head]
[body]
[p] Hello [/ p]
[/ Body]
[/ HTML]

Note: The use of brackets replace the angle brackets, but to ensure that the labels were in HTML format.

If you create this folder and open the browser will say 'Hello'. To make an object, a piece of software to produce both following files.

index.php

[? php?
/ / Include the class file containing the user
include ( 'user_class.php');

/ / Creates a new instance of the class of user
$ NewUser = new User;

/ / Call method get ()
Sat $ -> Welcome ();

?]

user_class.php

[? php?

User class (

/ / Methods

Welcome function () (
print "[HTML]";
print "[a]";
[Print / Head] ";
Print "[body]";
print "[p] Hello [/ p]";
"[/ Print body]";
print "[/ html]";
)

) / / End of class defined by the user
?]

If open index.php in the browser, but also displayed the word "welcome", but the weather by creating a new instance of class User (U.S. $), then get the call () method, the file that user_class.php. Without doubt, a very simple website as the building object-oriented approach on top form, but can the new methods in the file user_class.php, for example, allow users to save and connection introduced, and so on. You can then call methods that are interested in index.php or any other page of the site you think.

For example, if you create method checks whether the user is logged in, you can call this method from any page, I had to provide access control. So, if you control access to index.php, you can go into the file:

index.php

[? php?
/ / Includes class file containing the user
include ( 'user_class.php');

/ / Create a new instance of the User Class
$ NewUser = new User;

/ / Call the method checkAccess ()
U.S. $ -> checkAccess ();

/ / Receive Call () method
U.S. $ -> Welcome ();

?]

user_class.php

[? php?

User class (

/ / Methods

checkAccess function () (

Code go here, if the user registration, or verify that he / she is registered at the time.
)

Welcome function () (
print "[HTML]";
Print "[A]";
"[/ Printhead]";
print "[body]";
Print "[b] Hello [/ p] ";
"[/ Print body]";
print "[/ html]";
)

) / / End User Definition Class
?]

If users of web applications, for example, to create documents or photographs downloaded, you can create new classes of these requirements. To do this, you can create applications increasingly complex easy to maintain.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay


?>