Google
 

Thursday, February 08, 2007

Develop your own module on Site Engine

Some suggestion on how to develop a module on Site Engine.
The Site Engine government site is http://www.siteengine.net/

1. First set up a copy of the Site Engine on your local
Here are steps about how to set up the SiteEngine on your local box
a. Download a copy from here: SiteEngine 5.1.8 高级版环境集成
b. Just run the setup_Advanced.exe step by step
c. Access the http://localhost/install.php to setup the copy
Attention:
a. The MySql data base password is empty by default
b. You can find more detailed steps in 建站引擎安装手册(5.1.8)

2. Here are some docs you should read to get familiar with SiteEngine
a. 建站引擎安装手册(5.1.8)
b. SiteEngine 5.1.8 高级版用户手册


3. The interface of SiteEngine you have to use to develop your module is here:
SiteEngine二次开发说明文档(In the doc You can find all the interface of SiteEngine).

4. Some PHP books for you if you are new with PHP
OReilly Learning PHP 5 Jul 2004
OReilly PHPUnit Pocket Guide
OReilly Essential PHP Security Oct 2005
OReilly Web Database Applications with PHP and MySQL
OReilly PHP in a Nutshell Oct 2005
OReilly PHP Hacks Tips and Tools For Creating Dynamic Websites

5. Example code about how to use the interface of SiteEngine
a. Login the Site Engine as Administrator
b. Create a new channel in the channel management, for example: TestChannel
c. Edit TestChannel's content and leave it empty and save
d. Edit the template of TestChnnel.
e. Input the following template code and save the template:

[expression]myTesting()[/expression] {头部}
<table class="table" cellspacing ="0" cellpadding="0" border="0">
<tbody >
<tr class="margin">
<td valign="top" align ="right" width="205"> {公告}
<table class="table2" cellspacing ="0" cellpadding="0" border="0">
<tbody >
<tr >
<td >{用户登录信息} </td>
</tr >
</tbody >
</table >
<img height="5" src ="images/space.gif" width="0" border="0" /><br />
{
频道图像}{投票}{友情链接}{下级频道} </td>
<td valign="top" align ="left">
<table cellspacing="0" cellpadding ="0" width="98%" align="center" border ="0">
<tbody >
<tr >
<td class="navigation">{ 位置导航}</td >
</tr >
</tbody >
</table >
<img height="5" src ="/images/blank.gif" width="0" border="0" /><br />

<table class="table2" cellspacing ="1" cellpadding="0" align="center" border ="0">
<tbody >
<tr 381px>
<td class="font" valign ="top">
<p >$_SESSION['AddressList']</ p></td >
</tr >
</tbody >
</table ></td>
</tr >
</tbody >
</table >{底部}{浮标}

f. Create a PHP file with the following code and name it as AddressList.php. Move the AddressList.php file to the root folder of site engine. (The root folder is always the htdoc folder of Apache.)
1 <?php
2 session_start( );
3
4 function myTesting()
5 {
6 // Set reference to config.php
7 require 'config.php';
8 // setup data base connection
9 // $db_host ; servername
10 // $database ; data base server type
11 // $db_user ; data base user name
12 // $db_pass ; data base user password
13 // $db_name ; data base name
14 // $tablepre ; table prefix
15 //$connection = mysql_connect(DataBaseServer,UserName,Password);
16 $connection = mysql_connect( $db_host,$db_user,$db_pass);
17
18 // select data base
19 //mysql_select_db(DataBaseName, ConnectionObject);
20 mysql_select_db($db_name, $connection);
21
22 // execute query
23 // $result = mysql_query (SqlQueryString, ConnectionObject);
24 $sql = "Select * From boka_members";
25 $result = mysql_query ( $sql, $connection);
26 $AddressList ='';
27 // solve result
28 //while ($row = mysql_fetch_row($result))
29 while ($row = @ mysql_fetch_array($result))
30 {
31
32 // Add address data to result
33 $AddressList .= '
34 <tr>
35 <td >'.$row["lastvisit"]. '</td>
36 <td >'.$row["bday"].'</td>
37 <td >'.$row["location"].'</td>
38 <td >'.$row["email"].'</td>
39 <td >'.$row["telephone"].'</td>
40 <td >'.$row["username"].'</td>
41 <td >registered</td>
42 </tr>';
43
44 print "";
45 }
46 // $_SESSION['AddressList'] = "testing ";
47
48 $_SESSION['AddressList'] = '
49 <table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
50 <tbody>
51 <th>??à?</th>
52 <th>???ā??</th>
53 <th>1¤?
�nλ</th>
54 <th>Email</th>
55 <th>μ
</th>
56 <th>??§à?</th>
57 <th>?2???</th>'.
58 $AddressList .
59 '<tbody>
60 </table>';
61 // close connection
62 mysql_close($connection);
63 }
64
65

1 <?php
2 session_start( );
3
4 function myTesting()
5 {
6 // Set reference to config.php
7 require 'config.php';
8 // setup data base connection
9 // $db_host ; servername
10 // $database ; data base server type
11 // $db_user ; data base user name
12 // $db_pass ; data base user password
13 // $db_name ; data base name
14 // $tablepre ; table prefix
15 //$connection = mysql_connect(DataBaseServer,UserName,Password);
16 $connection = mysql_connect( $db_host,$db_user,$db_pass);
17
18 // select data base
19 //mysql_select_db(DataBaseName, ConnectionObject);
20 mysql_select_db($db_name, $connection);
21
22 // execute query
23 // $result = mysql_query (SqlQueryString, ConnectionObject);
24 $sql = "Select * From boka_members";
25 $result = mysql_query ( $sql, $connection);
26 $AddressList ='';
27 // solve result
28 //while ($row = mysql_fetch_row($result))
29 while ($row = @ mysql_fetch_array($result))
30 {
31
32 // Add address data to result
33 $AddressList .= '
34 <tr>
35 <td >'.$row["lastvisit"]. '</td>
36 <td >'.$row["bday"].'</td>
37 <td >'.$row["location"].'</td>
38 <td >'.$row["email"].'</td>
39 <td >'.$row["telephone"].'</td>
40 <td >'.$row["username"].'</td>
41 <td >registered</td>
42 </tr>';
43
44 print "";
45 }
46 // $_SESSION['AddressList'] = "testing ";
47
48 $_SESSION['AddressList'] = '
49 <table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
50 <tbody>
51 <th>Name</th>
52 <th>BirthDay</th>
53 <th>Location</th>
54 <th>Email</th>
55 <th>Telephone</th>
56 <th>UserName</th>
57 <th>Status</th>'.
58 $AddressList .
59 '<tbody>
60 </table>';
61 // close connection
62 mysql_close($connection);
63 }
64
65 ?>

g. Modify the Site Engine configuration file: config.php. You can find it in the htdoc folder of Apache.

//Change
$requirefiles = '';
//As
$requirefiles = 'AddressList.php';

h. Now Access the TestChannel of Site Engine site.
g. Then you will see a table of user data displays.

6. Knowledge to learn

A. [expression]callfunction()[/expression] means to execute the function: callfunction

B. In template, only one function can be put in the expression:[expression]callfunction()[/expression] and without semicolon at the end.

E.g. Correct:[expression]myTesting()[/expression]

Error: [expression]myTesting();[/expression]

C. The variable in template will be executed as php code and displays its value.

D. How to output the value of a variable

a. First define a variable as global

b. Set a value to the variable

c. Put the variable in template html code

E. How to execute a function in the template

a. Put the function in the expression :[expression]callfunction()[/expression]

b. Attention: only one function in each expresstion

c. Then put the expression at somewhere in the template

F. Access global variables: // comments: this method doesn't work

E.g.: variable $b,$GLOBALS['b']

G. Define a global variable

E.g.: global $a;

H. Declare a variable as global variable

E.g.: global $a; // Here should not assign any value to the variable

I. The code in the template has disabled to modify the value of the global variable with the key word global and $Globals['VariableName']. And function can only access the local variable.

Global keyword help:http://cn.php.net/global

J. The function cannot modify the value of global variables in the template. Therefore, I have to use session instead.

K. Access and store data in session Attention: before starting to use session, start the session first by the code:session_start( );E.g. $_SESSION['count'] = 1;

L. " " can only be used on single line and '' can be used on multi lines

M. Connect two string "."

N. The variable will not be replaced by its value in string

E.g. "$test" or '$test'

O. Attention the character encode in gb2312 or ANSI otherwise will cause unrecognizable characters

P. Using the $row = mysql_fetch_row($result), the $row cannot be accessed by key name.

However, the $row = @mysql_fetch_array($result) can do.

--
Happy day, happy life!

No comments: