PHPGRID3.0 user manual

Directory

PHPGRID3.0 user manual... 1

1 Introduction... 1

2 PHPGRID3.0 new features

3 Overview / Principles of

3 Installation

4 PHPGRID type

5 Custom Datagrid

6 Simple to use the sample

6.1 Only need to specify a SQL. 4

6.2 Only need to specify the table name and field name

6.3 Query

6.4 Display Control

6.5 Hidden line function

6.6 Use a Form

6.7 Access control

6.8 Caching is enabled

7.Examples of complex functions

7.1 Specify the type of form field

7.2 Specify the form displays a few columns

7.3 Additional attributes to form fields

7.4 Set up form validation

7.5 Use the online editor

7.6 Display multiple grid

7.7 The replacement of the skin

8Advanced Applications

8.1 To achieve the replacement of the field values

8.2 To rewrite the form

 

 

1 Introduction

Introduction PHPGRID is a rapid development of MIS system ( such as ERP, CRM, HR), site background, demo PHP class library, not only has data Add edit remove basic functions, but also automatically generates forms, sorting, paging, query, set permissions, cache functionality, but these features are Customized. For special needs, you can simply write a small amount of code to succeed PHPGRID . PHPGRID for those lazy and smart PHP Programmers, PHPGRID will make you free from the tasteless repetitive tasks out.

 

2 PHPGRID3.0 new features

3 Overview

  

      

 

Which Datagrid class is the core class, which Will be based on parameters provided by the construct SQL access to data from the database, and then connected into like the following , the final return. Generate the HTML example:

 

       <form action="" method="get" name="grid_search"><input

    type="hidden" name="datagrid_action" value="search" /> <input

    type="hidden" name="datagrid_page" value="1" />

 

<table>

    <tr>

       <td colspan="3"><span>Query</span></td>

    </tr>

    <tr>

       <td>Hero Name</td>

       <td><select name="ge_name_exp">

           <option value="=">=</option>

           <option value="!=">!=</option>

           <option value="LIKE">LIKE</option>

           <option value="LIKE %...%">LIKE %...%</option>

           <option value="NOT LIKE">NOT LIKE</option>

           <option value="IS NULL">IS NULL</option>

           <option value="IS NOT NULL">IS NOT NULL</option>

       </select></td>

       <td><input type="text" name="ge_name_value" size="25"

           class="textfield" id="ge_name_value" /></td>

    </tr>

 

    <tr>

       <td colspan="6">

       <div align="center"><input type="submit" name="Submit"

           value="Submit"> &nbsp;&nbsp;<input type="reset" name="Submit2"

           value="Reset"></div>

       </td>

    </tr>

</table>

<br>

</form>

<table summary=" table of Datagrid">

    <caption>Hero List</caption>

    <thead>

       <tr>

           <td scope="col"><a href="?datagrid_order=ge_userid">user ID</a></td>

           <td scope="col"><a href="?datagrid_order=ge_cityid">CIty ID</a></td>

           <td scope="col"><a href="?datagrid_order=ge_name">hero Nmae</a></td>

           <td scope="col"><a href="?datagrid_order=ge_equipment">Equipment information</a></td>

           <td width="10%" align="center" scope="col"><a href=#>Operating</a></td>

       <tr>

    </thead>

    <tbody>

       <tr>

           <td>2</td>

           <td>2222222222222</td>

           <td>Name</td>

           <td></td>

           <td align="center"><a title="body_control"

              href="?datagrid_action=edit&ge_id=1&">Edit</a> <a href="#"

              title="body_control"

              onClick="if(isconfirm()) window.location.href='?datagrid_action=delete&ge_id=1&'">Delete</a></td>

       </tr>

    </tbody>

    <tfoot>

       <tr>

           <td colspan="21">Count:30 &nbsp; Page</td>

       </tr>

    </tfoot>

</table>    

 

 

The file directory structure

      

   phpgrid3.0beta

   |

   |-...

   |

   +--cache                       storage of the cache directory                    

   +--js                               

   +--css                           Css style directory is used to control the interface of the skin                        

   +--examples                   of some typical examples                         

   +--images                     

   +--lang                          language pack support for multiple languages

   +--uploadfiles                 default file upload directory, you can specify in the code a directory                      

   |-...

   |-config.inc.php              global configuration file, set the database connection, time zone and language

   |-Dataview.php               Phpgrid3.0 the base class, the class just displays a table, similar to ASP.NET the dataview

   |-Datagrid.php                Phpgrid3.0 core file, inheritance, Dataview , Dataview all and attachment features

   |-Mysql.php                   connect MYSQL class library, support for PDO and MYSQL function, if you install the PDO extension will not use the MYSQL function

3 Installation

To Phpgrid3.0 compressed package released into your PHP application directory, where you need to introduce Datagrid.php can use. How to run the examples in the examples ? As follows:

1.In  MYSQL database to create any database

2.Then perform in the database  , import the data into the library

3.Then modify config.inc.php database connection

4.In the browser to access the example

4 PHPGRID type

Select Type If you want to generate has to add delete modify or even form page, then you need to instantiate the Datagrid class, and if you just want to display data, then you only need to instantiate in the Dataview class The simple Dtagrid example:

 

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->sql="SELECT * FROM `customer`";

$html=$expamle->display();

echo $html;

?>

 

Can also be added to this page with any other code, such as css style sheets, menu and so on. Example

 

<?php 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->sql="SELECT * FROM `customer`";

$html=$expamle->display();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

    <table >

      <tr>

        <td>

        <a href="?" >back</a>,&nbsp;&nbsp;Add form: 

        <a href="?datagrid_action=new" >here</a>

        </td>

      </tr>

    </table>

    <?php

    echo $html;

    ?>

</body>

</html>

 

5 custom Datagrid

You can easily set the Datagrid display, sorting, permissions, query or cache. There are set as follows:

 

 

6 Simple example of the use of

6.1. Only need to specify a SQL

 

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->sql="SELECT * FROM `customer`";

$html=$expamle->display();

echo $html;

?>

 

6.2 Only need to specify the table name and field name

 

<?php 

include_once('../Datagrid.php');

$expamle = new Datagrid();

$expamle->tables = "`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields = array("cus_id","cus_name","cus_address","cus_phone");

$expamle->fieldDisplays = array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

$html = $expamle->display();

echo $html;

?>

 

6.3 Query

 

<?php 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

 

//define search fields

$expamle->searchFields=array("cus_name"=>"Customer's name", "cus_address"=>"Address");

 

$html=$expamle->display();

echo $html;

?>

 

 

6.4 Display Control

 

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

$expamle->fields=array("cus_id","cus_name","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

 

$expamle->displayTableTitle=false; //no display Table Title

$expamle->displayOrder=false;      //no display order

$expamle->displayTableHeader=false;    //no display Table Header

$expamle->displaySearch=false;     //no display Search part

$expamle->displayControl=false;    //no display Control colums

$expamle->displayTableFooter=false;    //no display Footer

 

$html=$expamle->display();

echo $html;

?>

 

 

6.5 Hidden line function

 

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_address","cus_phone","cus_memo");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

$expamle->displayHideField=true;//先设置显示隐藏行

$expamle->hideField="cus_memo";/指定隐藏行的字段

 

$html=$expamle->display();

echo $html;

?>

 

 

6.6 Use a Form

 

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

 

// 设置表单属性

$expamle->formTable="`customer`";

$expamle->formFields=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

 

$html=$expamle->display();

echo $html;

?>

 

 

6.7 Access control

 

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

$expamle->role="v,d,a";//设置此属性来设定权限

 // define form

$expamle->formTable="`customer`";

$expamle->formFields=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

 

$html=$expamle->display();

echo $html;

?>

 

 

6.8 Enable Cache

Caching is enabled, read and write permissions on the cache directory

 

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->is_use_cache=true; //启用缓存

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

$html=$expamle->display();

echo $html;

?>

 

 

7. Examples of complex functions

7.1 Specify the type of form field

      

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_userid","cus_name","cus_email","cus_dept","cus_address","cus_phone","cus_pic");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_userid"=>"User","cus_email"=>"Email","cus_dept"=>"Department","cus_address"=>"Address","cus_phone"=>"Phone","cus_pic"=>"Pictrue");

$expamle->title="List of customer";

 

$expamle->formTable="`customer`";

$expamle->formFields=$expamle->fieldDisplays;

 

$user_list=array(1=>"Mark",2=>"Jockson",3=>"Tom",4=>"Sun");

$expamle->formTypes=array('cus_name' =>'text',

                       'cus_email' => 'text',

                       'cus_address' => 'text',

                       'cus_pic'=>'file',

                       'cus_phone'=>'text',

                       'cus_userid' => array('select',$user_list),

                       'cus_dept' => array ('list',array (1=>'HR',2=>'Information',3=>'BI'))

             );

 

 

//use livevalidation1.3 javascript libary

//how to use? See http://livevalidation.com/

$expamle->formFieldsValidates=array("cus_name"=>"Presence",

                                "cus_userid"=>"Presence",

                                "cus_email"=>"Email",

                                "cus_phone"=>"Numericality, {minimum: 11}");

 

$html=$expamle->display();

echo $html;

?>

 

      

The results are as follows:

      

      

7.2 Specify the form displays a few columns

      

<?php 

include_once('../Datagrid.php');

$expamle = new Datagrid();

$expamle->tables = "`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields = array("cus_id","cus_name","cus_address","cus_phone");

$expamle->fieldDisplays = array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title = "List of customer";

 

$expamle->formTable = "`customer`";

$expamle->formFields = $expamle->fieldDisplays;

$expamle->formColsNum = 3;//Specify the form displays three

$html = $expamle->display();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

 <table >

  <tr>

    <td><a href="?" >back</a>,&nbsp;&nbsp;Add form:  <a href="?datagrid_action=new" >here</a></td>

  </tr>

</table>

<?php

echo $html;

?>

 

</body>

</html>

 

      
Results:

      

      

 

7.3 To the additional attributes of form fields

      

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_email","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_email"=>"Email","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

 

$expamle->formTable="`customer`";

$expamle->formFields=array("cus_name"=>"Customer's name",

                        "cus_email"=>"Email",

                        "cus_address"=>"Address",

                        "cus_phone"=>"Phone");

 

//Here to set the properties of some of the fields in the form

$expamle->formAttributes=array("cus_name"=>'style="background:#FFFF00" ',

                                "cus_email"=>'readonly="true" style="background:#CCCCCC"');

 

$html=$expamle->display();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

 <table >

  <tr>

    <td><a href="?" >back</a>,&nbsp;&nbsp;Add form:  <a href="?datagrid_action=new" >here</a></td>

  </tr>

</table>

<?php

echo $html;

?>

 

</body>

</html>

 

      
 Results, pay attention to cus_name, and cus_email form fields:

      

      

7.4 Set up form validation

Very simple to set up form validation in Datagrid

      

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_email","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_email"=>"Email","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

 

$expamle->formTable="`customer`";

$expamle->formFields=array("cus_name"=>"Customer's name",

                        "cus_email"=>"Email",

                        "cus_address"=>"Address",

                        "cus_phone"=>"Phone");

//To use livevalidation1.3 javascript validation class libraries

//see http://livevalidation.com/

$expamle->formFieldsValidates=array("cus_name"=>"Presence",

                                "cus_email"=>"Email",

                                "cus_phone"=>"Numericality, {minimum: 11}");

 

$html=$expamle->display();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

 <table >

  <tr>

    <td><a href="?" >back</a>,&nbsp;&nbsp;Add form:  <a href="?datagrid_action=new" >here</a></td>

  </tr>

</table>

<?php

echo $html;

?>

 

</body>

</html>

      
Result:

      

 

7.5 Use the online editor

      

<?php 

 

include_once('../Datagrid.php');

$expamle=new Datagrid();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_userid","cus_name","cus_email","cus_dept","cus_address","cus_phone","cus_pic","cus_memo");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name",

                           "cus_userid"=>"User",

                           "cus_email"=>"Email",

                           "cus_dept"=>"Department",

                           "cus_address"=>"Address",

                           "cus_phone"=>"Phone",

                           "cus_pic"=>"Pictrue",

                           "cus_memo"=>"Memo");

$expamle->title="List of customer";

 

$expamle->formTable="`customer`";

$expamle->formFields=$expamle->fieldDisplays;

$expamle->formColsNum=1; //Set the form for a few columns

 

$user_list=array(1=>"Mark",2=>"Jockson",3=>"Tom",4=>"Sun");

$expamle->formTypes=array('cus_name' =>'text',

                       'cus_email' => 'text',

                       'cus_address' => 'simple_editor',

                       'cus_memo' => 'fckeditor',

                       'cus_pic'=>'file',

                       'cus_phone'=>'text',

                       'cus_userid' => array('select',$user_list),

                       'cus_dept' => array ('list',array (1=>'HR',2=>'Information',3=>'BI'))

             );

 

 

//use livevalidation1.3 javascript libary

//how to use? See http://livevalidation.com/

$expamle->formFieldsValidates=array("cus_name"=>"Presence",

                                "cus_userid"=>"Presence",

                                "cus_email"=>"Email",

                                "cus_phone"=>"Numericality, {minimum: 11}");

 

$html=$expamle->display();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

 <table >

  <tr>

    <td><a href="?" >back</a>,&nbsp;&nbsp;Add form:  <a href="?datagrid_action=new" >here</a></td>

  </tr>

</table>

<?php

echo $html;

?>

 

</body>

</html>

 

   
Result:

 

7.6 Display multiple grid

      

<?php 

//first

include_once('../Datagrid.php');

$gridObj=new Datagrid();

$gridObj->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$gridObj->fields=array("cus_id","cus_name","cus_address","cus_phone");

$gridObj->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$gridObj->title="List of customer";

$gridHtml=$gridObj->display();

 

//second

$viewObj=new Dataview();

$viewObj->sql="SELECT * FROM `customer` left join `user` on user_id=cus_userid";

$viewObj->fieldDisplays=array("cus_name"=>"Customer","user_name"=>"User","cus_pic"=>"Pictrue","cus_address"=>"Address","cus_phone"=>"Phone");

$viewHtml=$viewObj->display();

 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

<?php

echo $gridHtml;

?>

<p><p>

 

<?php

echo $viewHtml;

?>

</body>

</html>

      
Result:

  

 

7.7 The replacement of the skin

Datagrid built-table CSS style can be replaced through the replacement of these styles you need skin

 

<?php 

//first

include_once('../Datagrid.php');

$gridObj=new Datagrid();

$gridObj->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$gridObj->fields=array("cus_id","cus_name","cus_address","cus_phone");

$gridObj->fieldDisplays=array("cus_name"=>"Customer's name","cus_address"=>"Address","cus_phone"=>"Phone");

$gridObj->title="List of customer";

$gridHtml=$gridObj->display();

 

//second

$viewObj=new Dataview();

$viewObj->sql="SELECT * FROM `customer` left join `user` on user_id=cus_userid";

$viewObj->fieldDisplays=array("cus_name"=>"Customer","user_name"=>"User","cus_pic"=>"Pictrue","cus_address"=>"Address","cus_phone"=>"Phone");

$viewHtml=$viewObj->display();

 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

<title>Customers</title>

<script type="text/javascript">

    if(getCookie('style_css')!=null){

       document.write('<link type="text/css" rel="stylesheet" href="../css/'+getCookie('style_css')+'.css" />');

    }else{

       document.write('<link type="text/css" rel="stylesheet" href="../css/oranges-in-the-sky.css" />');

    }

    //cookies函数

    function SetCookie(name,value)

    {

        var Days = 30; 

        var exp  = new Date();    //new Date("December 31, 9998");

        exp.setTime(exp.getTime() + Days*24*60*60*1000);

        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();

    }

    function getCookie(name)

    {

        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));

         if(arr != null) return unescape(arr[2]); return null;

 

    }

</script>

 

 <body  >

 

<table      >

  <tr>

    <td>当前位置:<a href="?" >数据列表</a>,&nbsp;&nbsp;添加请点  <a href="?datagrid_action=new" >这里</a>&nbsp;&nbsp;&nbsp;更换皮肤

          <select name="style_cass" id="style_css" onChange="SetCookie('style_css',this.value);window.location.reload();" >

             <option  >请选择</option>

              <option value="oranges-in-the-sky">oranges-in-the-sky.css</option>

              <option value="bluedream">bluedream.css</option>

              <option value="classic_somehow">classic_somehow.css</option>

              <option value="itunes">itunes.css</option>

              <option value="mintgreen">mintgreen.css</option>

              <option value="seaglass">seaglass.css</option>

              <option value="pure_blue">pure_blue.css</option>

              <option value="dartblue">dartblue.css</option> 

        </select>

 </td>

  </tr>

</table>

<?php

echo $gridHtml;

?>

<p><p>

 

<?php

echo $viewHtml;

?>

</body>

</html>


Result:

 

8Advanced

The basic settings in the face of the complex business needs can not meet the operating requirements , due Phpgrid object-oriented techniques, so you can Datagrid and Dataview class . Using this method, to meet any special needs, and so no need to modify the base class code. When you inherited from Datagrid and Dataview class you can override any public methods. Here are some examples of extended.

 

8.1 To achieve the replacement of the field values

By rewrite the Datagrid classes repalceValue function can be replaced for each field value, such as adding color or hyperlink, the code:

  

<?php 

 

include_once('../Datagrid.php');

 

$GLOBALS['user_list']=array(1=>"Mark",2=>"Jockson",3=>"Tom",4=>"Sun");

 

 

/**

 * Inherited the Datagrid class and override the repalceValue function

 *

 * @author cdwei

 *

 */

class myclass extends Datagrid{

   

    //rewrite this function to custom   table body

    function repalceValue($row,$field,$value) {

       if($field=="cus_userid"){

           return $GLOBALS['user_list'][$value];

       }

       if($field=="cus_pic"){

           return '<img src="../'.$value.'"  width="30%" height="30%" />';

       }

       return $value;

    }

}

//The myclass classes instantiated inheritance

$expamle=new myclass();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_userid","cus_pic","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_userid"=>"User","cus_pic"=>"Pictrue","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

 

$expamle->formTable="`customer`";

$expamle->formFields=$expamle->fieldDisplays;

 

 

$expamle->formTypes=array('cus_name' =>'text',

                       'cus_email' => 'text',

                       'cus_address' => 'text',

                       'cus_pic'=>'file',

                       'cus_phone'=>'text',

                       'cus_userid' => array('select',$GLOBALS['user_list'])

             );

 

$html=$expamle->display();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

 <table >

  <tr>

    <td><a href="?" >back</a>,&nbsp;&nbsp;Add form:  <a href="?datagrid_action=new" >here</a></td>

  </tr>

</table>

<?php

echo $html;

?>

 

</body>

</html>

 

replaceValue function for each row in the data value, $ field the field name, $ value for the current value Results:

 

8.2 To rewrite the form

When you need a more complex form, the  need to expand the the the Datagrid classes formAdd formEdit functions, such as:

 

 

<?php 

 

include_once('../Datagrid.php');

 

$GLOBALS['user_list']=array(1=>"Mark",2=>"Jockson",3=>"Tom",4=>"Sun");

 

 

/**

 * extend Datagrid ,rewrite the public of function

 *

 * @author cdwei

 *

 */

class myclass extends Datagrid{

   

    /**

     * Rewritten to generate new forms

     */

    public function setNewFormHtml() {

       $html='

           <table   id="formHtml" >

                  <tr>

                   <td  colspan="4"  ><span >自己定义添加表单</span></td>

                 </tr>

                

                      <td  >Customer  name</td>

                       <td  ><input type="text" id="cus_name" name="cus_name"   value=""    > </td>

                      

                      <td  >User</td>

                       <td  ><select name="cus_userid"   id="cus_userid">

                         <option value=1>Mark</option>

                         <option value=2>Jockson</option>

                         <option value=3>Tom</option>

                         <option value=4>Sun</option>

                         </select> </td>

                       </tr>

                      <td  >Pictrue</td>

                       <td  >文件路径:<a href="../"  target="_blank"></a><br>

                      <input name="cus_pic" id="cus_pic" type="file"   />  </td>

                      

                      <td  >Address</td>

                       <td  ><input type="text" id="cus_address" name="cus_address"   value=""    > </td>

                       </tr>

                      <td  >Phone</td>

                       <td  ><input type="text" id="cus_phone" name="cus_phone"   value=""    > </td>

                      

                      <td  ></td>

                       <td  > </td>

                       </tr><tr >

                   <td colspan="4">

                     <div align="center">

                  <input type="submit" name="Submit" value="提交">

                   &nbsp;&nbsp;<input type="reset" name="Submit2" value="重置">

                     </div></td>

                </tr>     </table>

       ';

      

       return $html;

    }  

 

    /**

     * Rewritten

     */

    public function setEditFormHtml() {

       return $this->makeFormHtml('edit');

    }

   

}

//The myclass classes instantiated inheritance

$expamle=new myclass();

$expamle->tables="`customer`";

//aim to-> SELECT `cus_id` ,`cus_name`,`cus_address`,`cus_phone`  FROM `customer` 

$expamle->fields=array("cus_id","cus_name","cus_userid","cus_pic","cus_address","cus_phone");

$expamle->fieldDisplays=array("cus_name"=>"Customer's name","cus_userid"=>"User","cus_pic"=>"Pictrue","cus_address"=>"Address","cus_phone"=>"Phone");

$expamle->title="List of customer";

 

$expamle->formTable="`customer`";

$expamle->formFields=$expamle->fieldDisplays;

 

 

$html=$expamle->display();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link type="text/css" rel="stylesheet" href="../css/bluedream.css" />

<title>Customers</title>

 <body  >

 <table >

  <tr>

    <td><a href="?" >back</a>,&nbsp;&nbsp;Add form:  <a href="?datagrid_action=new" >here</a></td>

  </tr>

</table>

<?php

echo $html;

?>

 

</body>

</html>

 

 

Result: