Luyenkim.Net!

...where your idea grows!

 
  • Decrease font size
  • Default font size
  • Increase font size
Trang chủ arrow Công nghệ thông tin arrow Kinh nghiệm-thủ thuật arrow Overview of Components - Sơ lược về Com
Overview of Components - Sơ lược về Com PDF Print E-mail
(0 votes)
Thứ sáu, 23 Tháng một 2007
Article Index
Overview of Components - Sơ lược về Com
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8

Database Class Handlers

From Mambo Manual

In Mambo we provide a special class that relieves the developer of a lot of low level database work on tables. This special class is called mosDBTable and will have already been declared for you.

You don't use this class directly. In Object Oriented Programming (OOP) terms it's called an Abstract Class. We use this class to derive a new class which we will call mosInOut.

Create a file called mrx_inout.class.phpin the / /components/com_mrx_inout directory. Copy the following code into it and then we'll look at what is happening in this file.

1: <?php /* $Id: components.xml,v 1.6 2004/08/23 16:19:44 rcastley Exp $ */
2:
3: /**
4: * In/Out Board Main Class
5: * @package MOS−ROX
7: * @license http://www.gnu.org/copyleft/gpl.html. GNU Public License
8: * @version 4.5.110: */
11:
12: // ensure this file is being included by a parent file
13: defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
14:
15: /**
16: * MRX InOut table class
17: */
18: class mosInOut extends mosDBTable {
19: /** @var int Primary key */
20: var $id=null;
21: /** @var int */
22: var $user_id=null;
23: /** @var datetime */
24: var $time_out=null;
25: /** @var datetime */
26: var $time_in=null;
27: /** @var string */
28: var $location=null;
29: /** @var int */
30: var $catid=null;
31: /** @var int */
32: var $checked_out=null;
33: /** @var time */
34: var $checked_out_time=null;
35: /** @var int */
36: var $ordering=null;
37:
38: /**
39: * @param database A database connector object
40: */
41: function mosInOut() {
42: global $database;
43: $this−>mosDBTable( '#__mrx_inout', 'id', $database );
44: }
46: }
48: ?>

Line 18:

This line shows us the syntax for deriving a class in PHP. This tells PHP to create a class called mosInOut based on the existing class mosDBTable. Our class will 'inherit' all the properties and methods in the mosDBTable class. We could redefine all of them if we wanted to, but most have been written generically so that you don't. Only functions that work on information peculiar to your database table will be required to be 'overrided' (for example, the 'check' method).

Line 19−36:

All the comments in these lines are written in a format that an application called phpDocumentor can parse. We'll talk about this at the end of this book. In between the comments are a number of class variable declarations. What variables do I declare? That's easy. Declare a variable for each field in your database table. Make sure all the variables match the field names. Also make sure you set each variable to null otherwise problems will arise in some versions of 4.1.x of PHP.

Lines 41−44:

We need to create a class constructor method. This MUST be the same name as the class (you will often get errors or experience unusual behaviour if you forget).

Line 43:

To complete the construction of your class, you invoke the base class's constructor, passing it the name of your table, the primary key of your table and the database connector. 




Related news items:
Newer news items:
Older news items:

 

Please install Flash and turn on Javascript.

Đăng nhập






Lost Password?
No account yet? Register

Liên kết website

vinaora.com
onbai.com
Luyenkim.net
Thư viện cộng đồng
vnfolk.com
thietbidien.vn

Thống kê

We have 9 guests and 1 member online