Thule - 0.9.6
  • Welcome
  • Introduction
  • - MVC(Model-View-Controller)
    - Architecture of Framework
    - Flow Chart of Application
    - Services In One Server
    - Developing Guide
    - Features
  • Installation
  • Getting Started
  • - Direct Access HTTP
    - Router Access HTTP
    - Router Direct Access HTTP
    - Reserved Function
    - Convention
    - Bootstrap
    - Pack Javascript , CSS
  • Basic Modules
  • - Model
    - View
    - Controller
  • Libraries
  • - Router
    - Config
    - Response
    - Request
    - Database
    - Query
    - Cache
    - Debug
    - Log
    - Unit Test
    - Registry
    - Profile
  • Helper
  • - Auth
    - Calendar
    - Date
    - Error page
    - Email
    - Form
    - GeoIP
    - Google
    - Html Element
    - Html
    - Http
    - I18n
    - Image
    - Json
    - Jquery
    - Login
    - Layout
    - Locale
    - PHP to Javascript
    - Paging
    - Payflow
    - Soap
    - Text
    - Table
    - Uri
    - Upload
    - Validation
  • Plugins
  • - Smarty Template Engine
  • History
  • Home > Peer

    Peer class is help class for database handle in model.Sometimes we need the complex query and some special work after fetch data from database.At that time Peer class will be needed for that.

    Peer Directory

    Peer class is located in "models/peers" directory. "peers" directory is special directory,so you have to avoid the name when you create the directory in models.
    First, have a look in "peers" directory. There is samplepeer for helping your understand.
    If you want to use the static query, add the "QUERY_STATIC" to "select" function in class.

    class Samplepeer extends Peer {

          function __construct(Database $hconn){
                parent::__construct($hconn);
                $this->arrSql['sql_section']='thule';
          }
          function select_member($arrSql) {
                $arrSql['sql_key']='thule';
                return $this->select($arrSql);
          }

          function static_select_member($arrSql) {
                $arrSql['sql_section']='static_thule';
                $arrSql['sql_key']='thule';
                return $this->select($arrSql,QUERY_STATIC);
          }

          function update_member($arrSql) {
                $arrSql['sql_key']='thule_update';
                $this->execute($arrSql);
          }
    }

    Load Peer Class in model

                  $hconn=&$this->opendb('default');
                  $this->loadPeer("samplepeer",$hconn);
                  $this->Samplepeer->select_member($arr_sql);

    Create peer class and get query from xml


    When you create peer class ,you should extend the peer class to your own peer class. And you put the configure of "sql_section" to construct in your class

    class Samplepeer extends Peer {

          function __construct(Database $hconn){
                parent::__construct($hconn);
                $this->arrSql['sql_section']='thule';
          }
    }

    "sql_section" is a "<thule>" as some kind of category in database/queries/queries.xml.
    You can define the area of query scope,so it is very useful for huge scale system because of you can divide the person who should use the query and charges in a part of system to defined section of area.

    ...........
    <thule>
    ......
        <query key='thule'> select * from db_thule.tb_member where member_id='$member_id' </query>
    .......
    </thule>

    <blog>
    ......
        <query key='select_blog'> select * from tb_blog where member_id='?' </query>
    .......
    </blog>
    <home>
    ......
        <query key='select_home'> select * from tb_home where member_id='$member_id' </query>
    .......
    </home>
    ............

    "sql_key" is a key of query which you want to get.

    $arrSql['sql_key']='thule';

    If you use like above, you can get the query from below query

        <query key='thule'> select * from db_thule.tb_member where member_id='$member_id' </query>

    Static Query

    'query_values' parameter passed by $arr_sql is "preserved parameter" for static query.

    $arr_sql['query_values']=array(1,2,3);
    $result=$this->Sample->select_static_member($arr_sql);

    If you use like above, you can get the query from below query

        <query key='thule'> select * from db_thule.tb_member where a='?' and b='?' and c='?' </query>

    Get generated to be below

    select * from db_thule.tb_member where a='1' and b='2' and c='3'