From 1144e49b8e00fa75b1593e4637c9218d7d944b97 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 12 Jan 2014 21:33:46 +0100 Subject: Big quickstart doc overhaul, pt. 1 --- demos/quickstart/protected/pages/Fundamentals/Pages.page | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'demos/quickstart/protected/pages/Fundamentals/Pages.page') diff --git a/demos/quickstart/protected/pages/Fundamentals/Pages.page b/demos/quickstart/protected/pages/Fundamentals/Pages.page index 19900937..0f3a8d9f 100755 --- a/demos/quickstart/protected/pages/Fundamentals/Pages.page +++ b/demos/quickstart/protected/pages/Fundamentals/Pages.page @@ -5,7 +5,7 @@ Pages are top-most controls that have no parent. The presentation of pages are directly displayed to end-users. Users access pages by sending page service requests.

-Each page must have a template file. The file name suffix must be .page. The file name (without suffix) is the page name. PRADO will try to locate a page class file under the directory containing the page template file. Such a page class file must have the same file name (suffixed with .php) as the template file. If the class file is not found, the page will take class TPage. +Each page can have a template file. The file name suffix must be .page. The file name (without suffix) is the page name. PRADO will try to locate a page class file under the directory containing the page template file. Such a page class file must have the same file name (suffixed with .php) as the template file. If the class file is not found, the page will take class TPage.

PostBack

@@ -14,6 +14,18 @@ A form submission is called postback if the submission is made to the pag

+

CallBack

+

+A callback is a special form submission that, instead of requiring a full page reload on the browser, gets executed in the background through an ajax call. So, a callback is considered a postback too, but not vice versa. +
+A callback is handled as a normal postback but, instead of re-rendering the entire page, only the specific changes occured on the page gets sent back to the client and merged with the current browser page. A typical callback response consists of: +

    +
  1. one or more pieces of html code that will replace existing content on the page;
  2. +
  3. the javascript instructions needed to update the page;
  4. +
  5. some specific fields used by prado to mantain the pagestate and add the needed external resources (stylesheets, javascript files, etc..).
  6. +
+

+

Page Lifecycles

Understanding the page lifecycles is crucial to grasp PRADO programming. Page lifecycles refer to the state transitions of a page when serving this page to end-users. They can be depicted in the following statechart, -- cgit v1.2.3 From 1d729693961dfa4cf4da45a05d703b392dbcb47f Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 12 Jan 2014 23:45:18 +0100 Subject: Quickstart Doc overhaul, pt. 2: active controls + minor fixes --- demos/quickstart/protected/controls/TopicList.tpl | 1 + .../quickstart/protected/controls/es/TopicList.tpl | 4 +- .../quickstart/protected/controls/fr/TopicList.tpl | 2 +- .../quickstart/protected/controls/id/TopicList.tpl | 2 +- .../quickstart/protected/controls/ja/TopicList.tpl | 2 +- .../quickstart/protected/controls/pl/TopicList.tpl | 3 +- .../quickstart/protected/controls/zh/TopicList.tpl | 2 +- .../pages/ActiveControls/ActiveButton.page | 66 ------- .../protected/pages/ActiveControls/Home.page | 91 +-------- .../pages/ActiveControls/Introduction.page | 203 ++++++++++++++++++++- .../quickstart/protected/pages/Advanced/Error.page | 2 +- .../protected/pages/Controls/NewControl.page | 2 +- .../protected/pages/Controls/id/NewControl.page | 2 +- .../protected/pages/Database/ActiveRecord.page | 6 +- .../protected/pages/Database/id/ActiveRecord.page | 140 +++++++------- .../protected/pages/Database/pl/ActiveRecord.page | 66 +++---- .../protected/pages/Fundamentals/Pages.page | 4 +- .../pages/GettingStarted/CommandLine.page | 35 +++- 18 files changed, 356 insertions(+), 277 deletions(-) (limited to 'demos/quickstart/protected/pages/Fundamentals/Pages.page') diff --git a/demos/quickstart/protected/controls/TopicList.tpl b/demos/quickstart/protected/controls/TopicList.tpl index 586b7f75..dbb744b6 100755 --- a/demos/quickstart/protected/controls/TopicList.tpl +++ b/demos/quickstart/protected/controls/TopicList.tpl @@ -56,6 +56,7 @@

  • Validation Controls
  • List Controls
  • Data Controls
  • +
  • AJAX: Introduction
  • Active Controls (AJAX)
  • Writing New Controls
  • diff --git a/demos/quickstart/protected/controls/es/TopicList.tpl b/demos/quickstart/protected/controls/es/TopicList.tpl index be4be752..41359ac2 100755 --- a/demos/quickstart/protected/controls/es/TopicList.tpl +++ b/demos/quickstart/protected/controls/es/TopicList.tpl @@ -1,7 +1,7 @@
    -
    Comenzar
    +
    Comenzar
    • Introducción
    • ¿Que es PRADO?
    • @@ -27,7 +27,7 @@
      Básicos
      • Arquitectura
      • -
      • Componentes
      • +
      • Componentes
      • Controles
      • Páginas
      • Mádulos
      • diff --git a/demos/quickstart/protected/controls/fr/TopicList.tpl b/demos/quickstart/protected/controls/fr/TopicList.tpl index 44bb0b16..c2de4a9a 100755 --- a/demos/quickstart/protected/controls/fr/TopicList.tpl +++ b/demos/quickstart/protected/controls/fr/TopicList.tpl @@ -26,7 +26,7 @@
        Fundamentaux
        • Architecture
        • -
        • Composants
        • +
        • Composants
        • Contrôles
        • Pages
        • Modules
        • diff --git a/demos/quickstart/protected/controls/id/TopicList.tpl b/demos/quickstart/protected/controls/id/TopicList.tpl index bfc6ed64..fa00ee37 100755 --- a/demos/quickstart/protected/controls/id/TopicList.tpl +++ b/demos/quickstart/protected/controls/id/TopicList.tpl @@ -27,7 +27,7 @@
          Fundamental
          • Arsitektur
          • -
          • Komponen
          • +
          • Komponen
          • Kontrol
          • Halaman
          • Modul
          • diff --git a/demos/quickstart/protected/controls/ja/TopicList.tpl b/demos/quickstart/protected/controls/ja/TopicList.tpl index ccaf5c63..bfdbf129 100755 --- a/demos/quickstart/protected/controls/ja/TopicList.tpl +++ b/demos/quickstart/protected/controls/ja/TopicList.tpl @@ -27,7 +27,7 @@
            動作原理
            @@ -27,7 +26,7 @@
            Postawy
            • Architektura
            • -
            • Komponenty
            • +
            • Komponenty
            • Kontrolki
            • Strony
            • Moduły
            • diff --git a/demos/quickstart/protected/controls/zh/TopicList.tpl b/demos/quickstart/protected/controls/zh/TopicList.tpl index 00fa2280..6557a992 100755 --- a/demos/quickstart/protected/controls/zh/TopicList.tpl +++ b/demos/quickstart/protected/controls/zh/TopicList.tpl @@ -26,7 +26,7 @@
              基础概念
              • 框架结构
              • -
              • 部件
              • +
              • 部件
              • 控件
              • 页面
              • 模块
              • diff --git a/demos/quickstart/protected/pages/ActiveControls/ActiveButton.page b/demos/quickstart/protected/pages/ActiveControls/ActiveButton.page index d4167f6e..6385b658 100755 --- a/demos/quickstart/protected/pages/ActiveControls/ActiveButton.page +++ b/demos/quickstart/protected/pages/ActiveControls/ActiveButton.page @@ -24,70 +24,4 @@ events of an TActiveButton.

                -

                TActiveButton Class Diagram

                -

                The class diagram for TActiveButton is illustrated in the figure below. -Most active control that can perform callback request have a similar structure. -

                - - class="figure" - alt="TActiveButton class diagram" title="TActiveButton class diagram" /> - -

                TActiveButton is an extension of TButton -and implements two additional interfaces ICallbackEventHandler and -IActiveControl. The TActiveButton contains an instance of -TBaseActiveCallbackControl -available through the ActiveControl property of TActiveButton. -The following example set the callback parameter of the TActiveButton when -a callback request is dispatched. -

                - -<com:TActiveButton - Text="Click Me" - OnCallback="button_callback" - ActiveControl.CallbackParameter="value" /> - -

                In the OnCallback event handler method, the CallbackParameter -is available in the $param object.

                - -public function button_callback($sender, $param) -{ - echo $param->CallbackParameter; //outputs "value" -} - - -

                Adding Client Side Behaviour

                - -

                With in the ActiveControl property is an instance of -TCallbackClientSide available -as a property ClientSide of TActiveButton. -The ClientSide property contains sub-properties, such as RequestTimeOut, -and client-side javascript event handler, such as OnLoading, -that are used by the client-side when making a callback request. -The following example demonstrates the toggling of a "loading" indicator -when the client-side is making a callback request. -

                - - -<com:TClientScript PradoScripts="effects" /> -Loading... - -<com:TActiveButton - Text="Click Me" - OnCallback="button_callback" - ActiveControl.CallbackParameter="value" > - <prop:ClientSide - OnLoading="Element.show('callback_status')" - OnComplete="Element.hide('callback_status')" /> -</com:TActiveButton> - - -

                The example loads the "effects" javascript library using the -TClientScript component. -The ClientSide.OnLoading property value contains -javascript statement that uses the "effects" library to show the "Loading..." -span tag. Similarly, ClientSide.OnComplete property -value contains the javascript statement that hides the "Loading..." span tag. -See TCallbackClientSide for -further details on client-side property details. -

                diff --git a/demos/quickstart/protected/pages/ActiveControls/Home.page b/demos/quickstart/protected/pages/ActiveControls/Home.page index 92bdbca2..4a180620 100755 --- a/demos/quickstart/protected/pages/ActiveControls/Home.page +++ b/demos/quickstart/protected/pages/ActiveControls/Home.page @@ -1,6 +1,7 @@

                Active Controls (AJAX enabled Controls)

                -

                See the Introduction +

                +Active controls extends standard PRADO controls adding the ability to automatically update themselves on callbacks without the need of ad-hoc javascript calls. See the Introduction for a quick overview of the concept behind active controls (AJAX enabled controls). Most active controls have a property of ActiveControl and @@ -373,92 +374,4 @@ if Javascript was disabled on the client's browser.

                -

                Active Control Basic Infrastructure Classes

                -

                The following classes provide the basic infrastructure classes required to -realize the active controls. They can be useful to develop new active controls, but Prado users tipically don't need -to use them.

                -
                  -
                • -

                  TActiveControlAdapter

                  - -

                  - TActiveControlAdapter customizes the parent TControl class for active control classes. - It tracks changes in the viewstate values of the control and update - differences of the client-side HTML element attributes. -

                  -
                • - -
                • -

                  TActiveListControlAdapter

                  - -

                  - TActiveListControlAdapter allows the adapted list controls to change the selections - on the client-side during a callback request. -

                  -
                • - -
                • -

                  TActivePageAdapter

                  - -

                  - TActivePageAdapter process the page life-cycle for callback requests. -

                  -
                • - -
                • -

                  TBaseActiveControl

                  - -

                  - TBaseActiveControl class provided additional basic properties common for every - active control. An instance of TBaseActiveControl or its decendent - TBaseActiveCallbackControl is created by TActiveControlAdapter::getBaseActiveControl() - method. - The EnableUpdate property determines wether the active - control is allowed to update the contents of the client-side when the callback - response returns. -

                  -
                • - -
                • -

                  TCallbackResponseAdapter

                  - -

                  - TCallbackResponseAdapter alters the THttpResponse's outputs. - A TCallbackResponseWriter is used instead of the TTextWrite when - createHtmlWriter is called. Each call to createHtmlWriter will create - a new TCallbackResponseWriter. When flushContent() is called each - instance of TCallbackResponseWriter's content is flushed. - The callback response data can be set using the ResponseData property. -

                  -
                • - -
                - -

                Active Control Infrastructure Advanced Classes

                -

                The following classes provide advanced properties and events needed to realize the active controls. -A Prado user can use them to customize active controls behaviour and interact directly with the client side during a callback. -

                -
                  -
                • - TCallbackClientScript - methods to manipulate the client-side HTML elements, also includes methods - to invoke javascript Effects on HTML elements. -
                • - -
                • - TCallbackClientSide - is used to specify client-side callback request options and client-side event handlers. -
                • - -
                • - TCallbackEventParameter - provides the parameter passed during the callback request. -
                • - -
                • - TCallbackOptions - allows a common set of callback client-side options to be attached to one or more active controls. -
                • -
                -
                diff --git a/demos/quickstart/protected/pages/ActiveControls/Introduction.page b/demos/quickstart/protected/pages/ActiveControls/Introduction.page index 70cb9cbf..edc0b5bc 100755 --- a/demos/quickstart/protected/pages/ActiveControls/Introduction.page +++ b/demos/quickstart/protected/pages/ActiveControls/Introduction.page @@ -1,7 +1,204 @@ -

                Overview of Active Controls

                - -TODO: +

                AJAX: Introduction

                +

                +A classic webpage can only transfer data back to the server using an http postback request that requires a full page reload. This is a problem for web applications, since a synchronous page reload breaks the user interaction: the user must wait for the response to arrive and the page will lose its current status (the scrolling position, the currently focused control, etc..). +

                class="figure" /> +

                +A common solution to this problem is the use of AJAX (Asynchronous JavaScript and XML) callbacks. After the first full page load, the web application can make subsequents requests using javascript. The callback requests are asynchronous, so the user can continue to interact with the page while the response is loading. The response contains a list of changes that will be applied to the page "on the fly", like replacing existing elements with new content or add some css style to an existing element. +

                + +

                Interacting with a page on callback

                + +

                +PRADO has builtin support for AJAX callbacks in the form of Active Controls. These controls can trigger a callback request and have their properties (value, css style, attributes, ..) updated during a callback. +Before digging inside the list of Active Controls, it's good to have a look to how a page can be aware if the current request is a callback and how to interact with the page rendered on the client browser. +
                +The IsCallBack property of the TPage class exposes whether the current request being handled is the consequence of a callback, and the CallbackClient property provides many methods to update and alter the client-side content during a callback request. +

                + + +public function onClick($sender, $param) +{ + if($this->IsCallback) + { + $this->getCallbackClient()->hide($this->TextBox1); + } +} + + +

                Active Controls (AJAX enabled Controls)

                +

                +Active controls extends standard PRADO controls adding the ability to automatically update themselves on callbacks without the need of ad-hoc javascript calls. Active controls are reliant on a collection of javascript classes that gets added to the page automatically when needed. +

                + +

                +Most active controls have a ActiveControl.EnableUpdate property that determines whether the active control is allowed to update the contents of the client-side when the callback response returns. Depending on the control different properties can be updated. +

                + +

                +Some active controls can trigger a callback as a consequence of a clientside event (a button click, a checkbox being checked, a DOM event). The callback will first raise the normal serverside event associated to the control (eg: OnClick for a TButton or OnSelectedIndexChanged for a TRadioButtonList) and then the OnCallBack event. +The AutoPostBack property typically defaults to true for these controls. +

                +

                + +

                +Active controls have a ClientSide property that provides many subproperties to customize the controls and to hook some javascript code to the callback lifecycle, like showing a "Loading" logo at the start of a callback and hide it at the end. +

                + +

                TActiveButton Class Diagram

                +

                The class diagram for TActiveButton is illustrated in the figure below. +Most active control that can perform callback request have a similar structure. +

                + + class="figure" + alt="TActiveButton class diagram" title="TActiveButton class diagram" /> + +

                TActiveButton is an extension of TButton +and implements two additional interfaces ICallbackEventHandler and +IActiveControl. The TActiveButton contains an instance of +TBaseActiveCallbackControl +available through the ActiveControl property of TActiveButton. +The following example set the callback parameter of the TActiveButton when +a callback request is dispatched. +

                + +<com:TActiveButton + Text="Click Me" + OnCallback="button_callback" + ActiveControl.CallbackParameter="value" /> + +

                In the OnCallback event handler method, the CallbackParameter +is available in the $param object.

                + +public function button_callback($sender, $param) +{ + echo $param->CallbackParameter; //outputs "value" +} + + +

                Adding Client Side Behaviour

                + +

                With in the ActiveControl property is an instance of +TCallbackClientSide available +as a property ClientSide of TActiveButton. +The ClientSide property contains sub-properties, such as RequestTimeOut, +and client-side javascript event handler, such as OnLoading, +that are used by the client-side when making a callback request. +The following example demonstrates the toggling of a "loading" indicator +when the client-side is making a callback request. +

                + + +<com:TClientScript PradoScripts="effects" /> +Loading... + +<com:TActiveButton + Text="Click Me" + OnCallback="button_callback" + ActiveControl.CallbackParameter="value" > + <prop:ClientSide + OnLoading="Element.show('callback_status')" + OnComplete="Element.hide('callback_status')" /> +</com:TActiveButton> + + +

                The example loads the "effects" javascript library using the +TClientScript component. +The ClientSide.OnLoading property value contains +javascript statement that uses the "effects" library to show the "Loading..." +span tag. Similarly, ClientSide.OnComplete property +value contains the javascript statement that hides the "Loading..." span tag. +See TCallbackClientSide for +further details on client-side property details. +

                + +

                Active Control Basic Infrastructure Classes

                +

                The following classes provide the basic infrastructure classes required to +realize the active controls. They can be useful to develop new active controls, but Prado users tipically don't need +to use them.

                +
                  +
                • +

                  TActiveControlAdapter

                  + +

                  + TActiveControlAdapter customizes the parent TControl class for active control classes. + It tracks changes in the viewstate values of the control and update + differences of the client-side HTML element attributes. +

                  +
                • + +
                • +

                  TActiveListControlAdapter

                  + +

                  + TActiveListControlAdapter allows the adapted list controls to change the selections + on the client-side during a callback request. +

                  +
                • + +
                • +

                  TActivePageAdapter

                  + +

                  + TActivePageAdapter process the page life-cycle for callback requests. +

                  +
                • + +
                • +

                  TBaseActiveControl

                  + +

                  + TBaseActiveControl class provided additional basic properties common for every + active control. An instance of TBaseActiveControl or its decendent + TBaseActiveCallbackControl is created by TActiveControlAdapter::getBaseActiveControl() + method. + The EnableUpdate property determines wether the active + control is allowed to update the contents of the client-side when the callback + response returns. +

                  +
                • + +
                • +

                  TCallbackResponseAdapter

                  + +

                  + TCallbackResponseAdapter alters the THttpResponse's outputs. + A TCallbackResponseWriter is used instead of the TTextWrite when + createHtmlWriter is called. Each call to createHtmlWriter will create + a new TCallbackResponseWriter. When flushContent() is called each + instance of TCallbackResponseWriter's content is flushed. + The callback response data can be set using the ResponseData property. +

                  +
                • + +
                + +

                Active Control Infrastructure Advanced Classes

                +

                The following classes provide advanced properties and events needed to realize the active controls. +A Prado user can use them to customize active controls behaviour and interact directly with the client side during a callback. +

                +
                  +
                • + TCallbackClientScript + methods to manipulate the client-side HTML elements, also includes methods + to invoke javascript Effects on HTML elements. +
                • + +
                • + TCallbackClientSide + is used to specify client-side callback request options and client-side event handlers. +
                • + +
                • + TCallbackEventParameter + provides the parameter passed during the callback request. +
                • + +
                • + TCallbackOptions + allows a common set of callback client-side options to be attached to one or more active controls. +
                • +
                diff --git a/demos/quickstart/protected/pages/Advanced/Error.page b/demos/quickstart/protected/pages/Advanced/Error.page index 24c7ead0..391997fb 100755 --- a/demos/quickstart/protected/pages/Advanced/Error.page +++ b/demos/quickstart/protected/pages/Advanced/Error.page @@ -71,7 +71,7 @@ The naming convention for the template files used for all other exceptions is as Again, if the preferred language is not found, PRADO will try to use exception.html, instead.

                -CAUTION: When saving a template file, please make sure the file is saved using UTF-8 encoding. On Windows, you may use Notepad.exe to accomplish such saving. +CAUTION: When saving a template file, please make sure the file is saved using UTF-8 encoding. On Windows, you may use Notepad++ to accomplish such saving.
                diff --git a/demos/quickstart/protected/pages/Controls/NewControl.page b/demos/quickstart/protected/pages/Controls/NewControl.page index 10c789db..9a680f43 100755 --- a/demos/quickstart/protected/pages/Controls/NewControl.page +++ b/demos/quickstart/protected/pages/Controls/NewControl.page @@ -10,7 +10,7 @@ In general, there are two ways of writing new controls: composition of existing

                Composition of Existing Controls

                -Composition is the easiest way of creating new controls. It mainly involves instantiating existing controls, configuring them and making them the constituent components. The properties of the constituent components are exposed through subproperties. +Composition is the easiest way of creating new controls. It mainly involves instantiating existing controls, configuring them and making them the constituent components. The properties of the constituent components are exposed through subproperties.

                One can compose a new control in two ways. One is to extend TCompositeControl and override the TControl::createChildControls() method. The other is to extend TTemplateControl (or its child classes) and write a control template. The latter is easier to use and can organize the layout constituent components more intuitively, while the former is more efficient because it does not require parsing of the template. diff --git a/demos/quickstart/protected/pages/Controls/id/NewControl.page b/demos/quickstart/protected/pages/Controls/id/NewControl.page index ea083f6c..85c6eff0 100755 --- a/demos/quickstart/protected/pages/Controls/id/NewControl.page +++ b/demos/quickstart/protected/pages/Controls/id/NewControl.page @@ -10,7 +10,7 @@ Secara umum, ada dua cara penulisan kontrol baru: komposisi kontrol yang sudah a

                Komposisi Kontrol yang Sudah Ada

                -Komposisi adalah cara termudah membuat kontrol baru. Ia melibatkan terutama penurunan kontrol yang sudah ada, mengkonfigurasinya dan menjadikannya unsur komponen. Properti dari unsur komponen diperlihatkan melalui subproperti. +Komposisi adalah cara termudah membuat kontrol baru. Ia melibatkan terutama penurunan kontrol yang sudah ada, mengkonfigurasinya dan menjadikannya unsur komponen. Properti dari unsur komponen diperlihatkan melalui subproperti.

                Seseorang dapat menciptakan sebuah kontrol baru dalam dua cara. Pertama adalah memperluas TCompositeControl dan mengganti metode TControl::createChildControls(). Kedua adalah memperluas TTemplateControl (atau kelas anaknya) dan menulis template kontrol. Yang terakhir lebih mudah digunakan dan bisa mengatur tata letak unsur komponen lebih intuitif, sementara pembentuk lebih efisien karena ia tidak perlu menguraikan template. diff --git a/demos/quickstart/protected/pages/Database/ActiveRecord.page b/demos/quickstart/protected/pages/Database/ActiveRecord.page index 537c65e0..cf1485bd 100755 --- a/demos/quickstart/protected/pages/Database/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/ActiveRecord.page @@ -129,7 +129,7 @@ You may specify qualified table names. E.g. for MySQL, TABLE = "`database1`.

    Note: -Since version 3.1.3 you can also use a method table() to define the table name. +Since version 3.1.3 you can also use a method table() to define the table name. This allows you to dynamically specify which table should be used by the ActiveRecord. class TeamRecord extends TActiveRecord @@ -159,7 +159,7 @@ class UserRecord extends TActiveRecord { } } -

    More details regarding TComponent can be found in the Components documentation. +

    More details regarding TComponent can be found in the Components documentation. Later we shall use the getter/setters to allow for lazy loading of relationship objects.

    @@ -1128,7 +1128,7 @@ class PlayerRecord extends BaseFkRecord

    We first need to change the $skills=array() declaration to a private property $_skills (notice the underscore) and set it to null instead. This allows us to define the skills property using getter/setter methods -(see Components for details). The getSkills() +(see Components for details). The getSkills() getter method for the skills property will lazy load the corresponding skills foreign record when it is used as follows. Notice that we only do a lazy load when its $player_id is not null (that is, when the record is already fetched from the database or player id was already set). diff --git a/demos/quickstart/protected/pages/Database/id/ActiveRecord.page b/demos/quickstart/protected/pages/Database/id/ActiveRecord.page index 454aa3f9..8e81678e 100755 --- a/demos/quickstart/protected/pages/Database/id/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/id/ActiveRecord.page @@ -3,7 +3,7 @@

    Rekaman Aktif adalah obyek yang melapisi baris dalam tabel atau view database, melindungi akses database dan menambahkan logika domain pada data tersebut. - Dasar dari Rekaman Aktif adalah kelas bisnis, sebagai contoh, kelas + Dasar dari Rekaman Aktif adalah kelas bisnis, sebagai contoh, kelas Products, yang hampir menyamai struktur rekaman dari tabel database dibawahnya. Setiap Rekaman Aktif akan bertanggung jawab atas penyimpanan dan pengambilan data ke dan dari database.

    @@ -14,22 +14,22 @@

    Kapan Menggunakannya

    -

    Rekaman Aktif adalah pilihan yang baik untuk logika domain yang tidak terlalu rumit, +

    Rekaman Aktif adalah pilihan yang baik untuk logika domain yang tidak terlalu rumit, seperti membuat, membaca, memutakhirkan, dan menghapus. Derivasi dan validasi didasarkan pada satu rekaman yang bekerja denga baik dalam struktur ini. Rekaman Aktif mempunyai kuntungan utama dalam hal kesederhanaan. Mudah untuk membangun Rekaman Aktif, dan mudah untuk dimengerti.

    Akan tetapi, seiring dengan perkembangan logika bisnis Anda dalm hal kompleksitas, Anda akan segera ingin menggunakan hubungan langsung obyek Anda, koleksi, turunan, dan seterusnya. Ini tidak mudah diterapkan ke dalam Rekaman Aktif, dan menambahkannya sedikit demi sedikit menjadi sangat kacau. Argumen lain terhadap Rekaman Aktif adalah kenyataan bahwa ia menyandingkan desin obyek ke desain database. Ini menjadikannya lebih sulit untuk merefraktorisasi karena proyek terus berjalan.

    - -

    Alternatifnya adalah menggunakan Pemeta Data yang yang memisahkan aturan dari obyek bisnis dan bagaimana obyek ini disimpan. + +

    Alternatifnya adalah menggunakan Pemeta Data yang yang memisahkan aturan dari obyek bisnis dan bagaimana obyek ini disimpan. Prado menyediakan pilihan tambahan antara Rekaman Aktif dan - Pemeta Data SqlMap. - Pemeta Data SqlMap bisa dipakai untuk mengambil obyek Rekaman Aktif, hasilnya; obyek Rekaman Aktif ini bisa dipakai untuk memutakhirkan database. + Pemeta Data SqlMap. + Pemeta Data SqlMap bisa dipakai untuk mengambil obyek Rekaman Aktif, hasilnya; obyek Rekaman Aktif ini bisa dipakai untuk memutakhirkan database. "Hubungan" antara Rekaman Aktif dan SqlMap digambarkan dalam diagram berikut. Lebih rinci mengenai Pemeta Data SqlMap dapat ditemukan dalam Manual SqlMap. alt="Rekaman Aktif dan SqlMap DataMapper" id="fig:diagram.png" class="figure"/>

    - +

    Kelas Rekaman Aktif berfungsi untuk melakukan tugas-tugas berikut.

    @@ -41,22 +41,22 @@

    Implikasi Desain

    -Implementasi Prado terhadap Rekaman Aktif tidak memelihara identitas referensial. Setiap obyek diperoleh menggunakan Rekaman Aktif pada data dalam database. Sebagai contoh, jika Anda meminta kustomer tertentu dan mendapatkan kembali obyek Customer, kali berikutnya Anda meminta kustomer itu, Anda akan kembali mendapatkan turunan lain dari obyek Customer. Ini berarti bahwa perbandingan tepat (misalnya menggunakan ===) akan mengembalikan false, sementara perbandingan bebas (misalnya menggunakan ==) akan mengembalikan true jika nilai obyek sama menurut perbandingan bebas. +Implementasi Prado terhadap Rekaman Aktif tidak memelihara identitas referensial. Setiap obyek diperoleh menggunakan Rekaman Aktif pada data dalam database. Sebagai contoh, jika Anda meminta kustomer tertentu dan mendapatkan kembali obyek Customer, kali berikutnya Anda meminta kustomer itu, Anda akan kembali mendapatkan turunan lain dari obyek Customer. Ini berarti bahwa perbandingan tepat (misalnya menggunakan ===) akan mengembalikan false, sementara perbandingan bebas (misalnya menggunakan ==) akan mengembalikan true jika nilai obyek sama menurut perbandingan bebas.

    Implikasi desain ini terkait dengan pertanyaan berikut. -"Anda pikir kustomer sebagai obyek, di mana hanya satu, +"Anda pikir kustomer sebagai obyek, di mana hanya satu, atau Anda pikir obyek yang Anda operasikan sebagai duplikat dari database?" -Pemetaan O/R lain akan mengartikan bahwa hanya ada satu obyek Kustomer dengan custID 100, dan secara literal ia adalah kustomer. -Jika Anda mendapatkan kustomer dan mengubah field-nya, maka Anda sekarang telah mengubah kustomer itu. -"Itu berbatasan dengan: Anda telah mengubah duplikat kustomer ini, tapi bukan pada duplikat itu. +Pemetaan O/R lain akan mengartikan bahwa hanya ada satu obyek Kustomer dengan custID 100, dan secara literal ia adalah kustomer. +Jika Anda mendapatkan kustomer dan mengubah field-nya, maka Anda sekarang telah mengubah kustomer itu. +"Itu berbatasan dengan: Anda telah mengubah duplikat kustomer ini, tapi bukan pada duplikat itu. Dan jika dua orang memutakhirkan kustomer pada dua duplikat obyek, siapapun yang memutakhirkan pertama kali, atau mungkin yang terakhir yang menang." [A. Hejlsberg 2003]

    Database yang Didukung

    -Implementasi Rekaman Aktif memanfaatkan kelas Prado DAO untuk akses data. -Implementasi Rekaman Aktif saat ini mendukung database sebagai berikut. +Implementasi Rekaman Aktif memanfaatkan kelas Prado DAO untuk akses data. +Implementasi Rekaman Aktif saat ini mendukung database sebagai berikut.

    • MySQL 4.1 atau lebih tinggi
    • @@ -69,8 +69,8 @@ Implementasi Rekaman Aktif saat ini mendukung database sebagai berikut.

      Mendefinisikan Rekaman Aktif

      Mari kita anggap tabel - "users" berikut yang berisi dua kolom bernama "username" dan "email", - di mana "username" juga merupakan kunci primer. + "users" berikut yang berisi dua kolom bernama "username" dan "email", + di mana "username" juga merupakan kunci primer. CREATE TABLE users ( @@ -88,7 +88,7 @@ class UserRecord extends TActiveRecord public $username; //kolom bernama "username" dalam tabel "users" public $email; - + /** * @return TActiveRecord active record finder instance */ @@ -116,7 +116,7 @@ Anda dapat menetapkan nama-nama tabel yang memenuhi syarat. Contohnya untuk MySQ class UserRecord extends TActiveRecord { ... //definisi yang sudah ada seprti di atas - + private $_level; public function setLevel($value) { $this->_level=TPropertyValue::ensureInteger($value,0); @@ -126,18 +126,18 @@ class UserRecord extends TActiveRecord { } } -

      Lebih jelas mengenai TComponent dapat ditemukan dalam Dokumentasi komponen. +

      Lebih jelas mengenai TComponent dapat ditemukan dalam Dokumentasi komponen. Nantinya kita harus dapat menggunakan pengambil/penyetel guna membolehkan pengambilan malas atas obyek yang berhubungan.

      Info: TActiveRecord juga dapat bekerja dengan view database dengan menetapkan konstan TABLE terkait ke nama view. Akan tetapi, obyek yang dikembalikan dari view hanya-baca, memanggil metode -save() atau delete() akan memunculkan eksepsi. +save() atau delete() akan memunculkan eksepsi.

      - Metode statis finder() mengembalilkan turunan UserRecord + Metode statis finder() mengembalilkan turunan UserRecord yang dapat dipakai untuk mengambil rekaman dari database. Pengambilan rekaman menggunakan metode finder akan didiskusikan nanti. Metode statis TActiveRecord::finder() mengambil nama kelas Rekaman Aktif sebagai parameter.

      @@ -152,7 +152,7 @@ obyek yang dikembalikan dari view hanya-baca, memanggil metode $dsn = 'pgsql:host=localhost;dbname=test'; //Postgres SQL $conn = new TDbConnection($dsn, 'dbuser','dbpass'); TActiveRecordManager::getInstance()->setDbConnection($conn); - +

      Alternatifnya, Anda dapat membuat basis kelas dan mengganti metode getDbConnection() untuk mengembalikan koneksi database. Ini adalah cara sederhana untuk mengijinkan koneksi database multipel. Kode berikut mendemonstrasikan penetapan koneksi database dalam sebuah basis kelas (tidak perlu menyetel koneksi DB di manapun juga). @@ -178,13 +178,13 @@ class MyDb2Record extends TActiveRecord return $conn; } } - +

      Menggunakan application.xml di dalam Kerangka Kerja Prado

      - Koneksi database standar dapat juga dikonfigurasi menggunakan tag <module> dalam application.xml + Koneksi database standar dapat juga dikonfigurasi menggunakan tag <module> dalam application.xml atau config.xml seperti berikut. @@ -192,8 +192,8 @@ class MyDb2Record extends TActiveRecord - - + +

      Tip: Atribut EnableCache ketika disetel ke "true" akan melakukan cache meta data tabel, yakni nama kolom tabel, indeks dan batasan yang disimpan dalam cache dan dipakai ulang. Anda harus membersihkan atau mematikan cache jika Anda ingin melihat perubahan terhadap definisi tabel Anda. Modul cache juga harus didefinisikan agar cache berfungsi.
      @@ -207,13 +207,13 @@ class MyDb2Record extends TActiveRecord Username="dbuser" Password="dbpass" /> - - - + +

      @@ -299,10 +299,10 @@ $criteria->Offset = 20;
      Catatan: Untuk MSSQL dan saat Limit serta Offset berisi nilai integer positif. Query aktual yang dijalankan diubah oleh kelas - -berdasarkan pada +berdasarkan pada http://troels.arvin.dk/db/rdbms/ untuk mengemulasikan kondisi Limit dan Offset.
      @@ -332,11 +332,11 @@ $finder->find('Username = ? AND Password = ?', $name, $pass); $finder->findAllByAge($age); $finder->findAll('Age = ?', $age); - +
      Tip: Anda juga dapat menggunakan kombinasi AND dan OR sebagai kondisi dalam metode dinamis.
      - +

      findBySql() dan findAllBySql()

      Mencari rekaman menggunakan SQL penuh di mana findBySql() mengembalikan Rekaman Aktif dan findAllBySql()mengembalikan array obyek rekaman. Untuk setiap kolom yang dikembalikan, kelas Rekaman Aktif terkait harus mendefinisikan variabel atau properti untuk setiap nama kolom terkait. @@ -371,7 +371,7 @@ Obyek dimutakhirkan dengan kunci primer dari tabel itu yang berisi definisi yang Sebagai contoh, jika Anda menyisipkan sebuah rekaman baru ke dalam tabel MySQL yang kolomnya didefinisikan dengan "autoincrement", obyek Rekaman Aktif akan dimutakhirkan dengan nilai yang ditambahkan.

    -Untuk memutakhirkan rekaman dalam database, cukup ubah satu atau lebih properti obyek Rekaman Aktif yang sudah diambil dari database dan kemudian panggil metode save(). +Untuk memutakhirkan rekaman dalam database, cukup ubah satu atau lebih properti obyek Rekaman Aktif yang sudah diambil dari database dan kemudian panggil metode save(). $user = UserRecord::finder()->findByName('admin'); @@ -392,7 +392,7 @@ Kapan saja Anda memanggil metode save() pada obyek TActiveRecord, obyek

    Menghapus rekaman yang sudah ada

    Untuk menghapus rekaman yang sudah ada dan diambil, cukup panggil metode delete(). - Anda juga dapat menghapus rekaman dalam database dengan kunci primer tanpa mengambil rekaman apapun menggunakan metode deleteByPk() (dan metode yang sama deleteAllByPks()). + Anda juga dapat menghapus rekaman dalam database dengan kunci primer tanpa mengambil rekaman apapun menggunakan metode deleteByPk() (dan metode yang sama deleteAllByPks()). Sebagai contoh, untuk menghapus satu atau beberapa rekaman dengan menggunakan satu atau lebih kunci primer.

    @@ -457,8 +457,8 @@ TActiveRecord menawarkan dua event, OnCreateCommand dan OnExecuteCo

    -Event OnExecuteCommand dimunculkan ketika perintah dijalankan dan hasil dari database dikembalikan. Obyek parameter TDataGatewayResultEventParameter -dari properti Result berisi data yang dikembalikan dari database. +Event OnExecuteCommand dimunculkan ketika perintah dijalankan dan hasil dari database dikembalikan. Obyek parameter TDataGatewayResultEventParameter +dari properti Result berisi data yang dikembalikan dari database. Data yang dikembalikan dapat diubah dengan setelan properti Result.

    @@ -491,7 +491,7 @@ function logger($sender,$param) } TActiveRecord::finder('MyRecord')->OnExecuteCommand[] = 'logger'; $obj->OnExecuteCommand[] = array($logger, 'log'); //setiap PHP callback yg benar. -
    +

    Hubungan Rekaman Aktif

    @@ -507,7 +507,7 @@ Dalam bagian berikut kita akan menganggap hubungan tabel antara class="figure" /> -

    Tujuannya adalah untuk mendapatkan model obyek yang mewakili ke beberapa derajat hubungan entitas dalam gambar di atas. +

    Tujuannya adalah untuk mendapatkan model obyek yang mewakili ke beberapa derajat hubungan entitas dalam gambar di atas.

    class="figure" /> @@ -534,7 +534,7 @@ CREATE TABLE bar

    Pemetaan Kunci Asing

    -

    Hubungan entitas antara tabel Teams dan Players adalah apa yang dikenal sebagai hubungan 1-M. Yaitu, satu Tim dapat berisi 0 atau lebih Pemain. Dalam batasan hubungan obyek, kita katakan bahwa obyek TeamRecord memiliki banyak obyek PlayerRecord. +

    Hubungan entitas antara tabel Teams dan Players adalah apa yang dikenal sebagai hubungan 1-M. Yaitu, satu Tim dapat berisi 0 atau lebih Pemain. Dalam batasan hubungan obyek, kita katakan bahwa obyek TeamRecord memiliki banyak obyek PlayerRecord. (Perhatikan kebalikan dari arah hubungan antara tabel dan obyek.)

    @@ -548,7 +548,7 @@ class TeamRecord extends TActiveRecord const TABLE='Teams'; public $name; public $location; - + public $players=array(); // deklarasi ini tidak diperlukan lagi sejak v3.1.2 //mendefinisikan anggota $player yang memiliki hubungan banyak dengan PlayerRecord @@ -616,7 +616,7 @@ Metode with_xxx() (di mana xxx adalah nama properti hubungan,

    Catatan: Penting untuk dimengerti bahwa obyek terkait diambil menggunakan query tambahan. Query pertama mengambil obyek sumber, misalnya TeamRecord dalam contoh kode di atas. -Query kedua dipakai untuk mengambil obyek PlayerRecord terkait. +Query kedua dipakai untuk mengambil obyek PlayerRecord terkait. Penggunaan dua query mirip dengan query tunggal menggunakan Left-Outer join dengan eksepsi bahwa hasil null pada tabel kanan tidak dikembalikan. Konsekuensi pemakaian dua tau lebih query adalah kondisi agregat dan join tidak layak menggunakan Rekaman Aktif. Untuk query di luar lingkup Rekaman Aktif, Pemeta Data SqlMap diapat dupertimbangkan.
    @@ -634,9 +634,9 @@ Kode berikut mendefinisikan kelas PlayerRecord lengkap dengan 3 hubunga class PlayerRecord extends TActiveRecord { const TABLE='Players'; - public $player_id; - public $age; - public $team_name; + public $player_id; + public $age; + public $team_name; public $team; // deklarasi ini tidak diperlukan lagi sejak v3.1.2 public $skills=array(); // deklarasi ini tidak diperlukan lagi sejak v3.1.2 @@ -656,9 +656,9 @@ class PlayerRecord extends TActiveRecord }

    -Properti $RELATIONS dari PlayerRecord mendefinisikan properti $team milik TeamRecord. -Array $RELATIONS juga mendefinisikan dua hubungan lainnya yang nanti akan kita uji dalam seksi di bawah ini. -Dalam array(self::BELONGS_TO, 'TeamRecord'), elemen pertama mendefinisikan tipe hubungan, dalam hal ini self::BELONGS_TO dan +Properti $RELATIONS dari PlayerRecord mendefinisikan properti $team milik TeamRecord. +Array $RELATIONS juga mendefinisikan dua hubungan lainnya yang nanti akan kita uji dalam seksi di bawah ini. +Dalam array(self::BELONGS_TO, 'TeamRecord'), elemen pertama mendefinisikan tipe hubungan, dalam hal ini self::BELONGS_TO dan elemen kedua adalah string 'TeamRecord' yang terkait ke nama kelas dari kelas TeamRecord. Obyek pemain dengan obyek tim terkait dapat diambil serperti berikut.

    @@ -703,7 +703,7 @@ class ProfileRecord extends TActiveRecord

    Intinya, ada hubungan "belongs to" untuk obyek yang mengaitkan entitas yang memmpunyai kolom yakni kunci asing. Dalam keadaan tertentu, kita melihat bahwa tabel Profiles mempunyai batasan kunci asing pada kolom player_id yang terkait ke tabel Players kolom player_id. Selanjutnya, obyek ProfileRecord memiliki properti ($player) yang adalah milik obyek PlayerRecord. -Demikian juga, tabel Players mempunyai batasan kunci asing pada kolom team_name yang terkait ke tabel Teams kolom name. +Demikian juga, tabel Players mempunyai batasan kunci asing pada kolom team_name yang terkait ke tabel Teams kolom name. Kemudian, obyek PlayerRecord mempunyai properti ($team) yang adalah milik obyek TeamRecord.

    @@ -756,13 +756,13 @@ dua elemen tambahan ini mirip seperti parameter yang dikirimkan ke metode fi Obyek dapat dengan mudah menangani field multi nilai dengan menggunakan koleksi sebagai nilai field. Database relasional tidak memiliki fitur ini dan dibatasi hanya ke field nilai-tunggal. Ketika Anda memetakan asosiasi satu-ke-banyak, Anda bisa menangani ini menggunakan hubungan has many, intinya menggunakan kunci asing untuk nilai-tunggal akhir dari asosiasi. Tapi asosiasi banyak-ke-banyak tidak bisa melakukan ini karena tidak ada nilai-tunggal akhir ke kunci asing yang dipegangnya.

    -Jawabannya adalah resolusi klasik yang telah dipakai oleh orang selama dekade ini yakni: buat tabel ekstra (tabel asosiasi) untuk merekam asosiasi. +Jawabannya adalah resolusi klasik yang telah dipakai oleh orang selama dekade ini yakni: buat tabel ekstra (tabel asosiasi) untuk merekam asosiasi. Ide dasarnya adalah menggunakan tabel asosiasi untuk menyimpan asosiasi. Tabel ini memiliki ID kunci asing untuk dua tabel yang dikaitkan bersama, masing-masing memiliki pasangan dari obyek yang diasosiasikan.

    Tabel asosiasi tidak mempunyai kaitan obyek dalam-memori dan kunci primernya adalah gabungan dari dua kunci primer dari tabel yang diasosiasikan. -Dalam batasan yang sederhana, tuntuk mengambil data dari tabel asosiasi, Anda melakukan dua query (secara umum, ini juga bisa dicapai menggunakan satu query yang terdiri dari join). -Anggap pengambilan koleksi SkillRecord untuk daftar obyek PlayerRecord. +Dalam batasan yang sederhana, tuntuk mengambil data dari tabel asosiasi, Anda melakukan dua query (secara umum, ini juga bisa dicapai menggunakan satu query yang terdiri dari join). +Anggap pengambilan koleksi SkillRecord untuk daftar obyek PlayerRecord. Dalam hal ini, Anda melakukan query dalam dua tahap. Tahap pertama meng-query tabel Players untuk mencari seluruh baris dari pemain yang Anda inginkan. Tahap kedua mencari obyek SkillRecord ID pemain terkait untuk setiap barisnya dalam tabel asosiasi Player_Skills menggunakan sebuah inner join.

    @@ -794,7 +794,7 @@ class SkillRecord extends TActiveRecord

    Properti statis $RELATIONS dari SkillRecord mendefinisikan bahwa properti $players memiliki banyak PlayerRecords melalui tabel asosiasi 'Player_Skills'. Dalam array(self::MANY_TO_MANY, 'PlayerRecord', 'Player_Skills'), elemen pertama mendefinisikan tipe hubungan, dalam hal ini self::HAS_MANY, -elemen kedua adalah string 'PlayerRecord' yang terkait ke nama kelas dari kelas PlayerRecord, dan elemen ketiga adalah nama dari nama tabel asosiasi. +elemen kedua adalah string 'PlayerRecord' yang terkait ke nama kelas dari kelas PlayerRecord, dan elemen ketiga adalah nama dari nama tabel asosiasi.

    Catatan: @@ -815,22 +815,22 @@ Metode with_xxx() (di mana xxx adalah nama properti hubungan,

    Untuk tabel asosiasi yang mererefensi dirinya sendiri, yaitu titik asosiasi ke tabel yang sama. Sebagai contoh, anggap tabel items dengan item terkait M-N melalui tabel asosiasi related_items. Sintaks dalam contoh berikut adalah benar untuk database PostgreSQL. Untuk database lain, lihat dokumentasinya masing-masing untuk mendefinisikan batasan kunci asing. -CREATE TABLE items +CREATE TABLE items ( - "item_id" SERIAL, + "item_id" SERIAL, "name" VARCHAR(128) NOT NULL, PRIMARY KEY("item_id") ); -CREATE TABLE "related_items" +CREATE TABLE "related_items" ( - "item_id" INTEGER NOT NULL, - "related_item_id" INTEGER NOT NULL, - CONSTRAINT "related_items_pkey" PRIMARY KEY("item_id", "related_item_id"), + "item_id" INTEGER NOT NULL, + "related_item_id" INTEGER NOT NULL, + CONSTRAINT "related_items_pkey" PRIMARY KEY("item_id", "related_item_id"), CONSTRAINT "related_items_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "items"("item_id") ON DELETE CASCADE ON UPDATE NO ACTION - NOT DEFERRABLE, + NOT DEFERRABLE, CONSTRAINT "related_items_related_item_id_fkey" FOREIGN KEY ("related_item_id") REFERENCES "items"("item_id") ON DELETE CASCADE @@ -839,7 +839,7 @@ CREATE TABLE "related_items" ); -

    Nama tabel asosiasi dalam elemen ketiga dari array hubungan dapat berisi nama kolom tabel asing. Kolom yang didefinisikan dalam tabel asosiasi harus juga didefinisikan dalam kelas rekaman (contohnya properti $related_item_id terkait ke kolom related_item_id dalam tabel related_items). +

    Nama tabel asosiasi dalam elemen ketiga dari array hubungan dapat berisi nama kolom tabel asing. Kolom yang didefinisikan dalam tabel asosiasi harus juga didefinisikan dalam kelas rekaman (contohnya properti $related_item_id terkait ke kolom related_item_id dalam tabel related_items).

    class Item extends TActiveRecord @@ -849,18 +849,18 @@ class Item extends TActiveRecord public $details; //id item asing tambahan didefinisikan dalam tabel asosiasi - public $related_item_id; + public $related_item_id; public $related_items=array(); // deklarasi ini tidak diperlukan lagi sejak v3.1.2 public static $RELATIONS=array ( - 'related_items' => array(self::MANY_TO_MANY, + 'related_items' => array(self::MANY_TO_MANY, 'Item', 'related_items.related_item_id'), ); }
    Tip: -Kunci gabungan dalam tabel asing dapat ditetapkan sebagai nilai dipisahkan koma diantara kurung buka/tutup. Contohnya 'related_items.(id1,id2)'. +Kunci gabungan dalam tabel asing dapat ditetapkan sebagai nilai dipisahkan koma diantara kurung buka/tutup. Contohnya 'related_items.(id1,id2)'.