Choose your database:
AnySQL
MySQL
MS SQL Server
PostgreSQL
SQLite
Firebird
Oracle
SQL Anywhere
DB2
MaxDB

Subscribe to our news:
Partners
Testimonials
Mike Little: "Great product, thank you for your great work and sharing".
Steve Morton: "First let me thank you for making this application Free. Best deal I have ever see for what it does".

More

Add your opinion

PHP Generator for MySQL online Help

Prev Return to chapter overview Next

OnGetCustomTemplate

This event allows you to customize almost any part of the generated application using an own template instead of the default one.

 

Signature:

function OnGetCustomTemplate ($part, $mode, &$result, &$params)

 

Parameters:

$part

The part of the page to be affected by the template.

$mode

The current state of the webpage the template to be used.

$result

The path to the file to be used as template according to the components/templates/custom_templates folder.

$params

An associative array of additional parameters you want to assign to the template.

 

PHP Generator uses Smarty 2.0 as template language. If you are not familiar with web template engines, you might want to start here.

 

Our Feature Demo provides a number of live examples of customized templates. We would recommend you to study them carefully before trying to customize your application.

 

To customize a webpage, you need to:

 

create a new template to be used for this webpage;
instruct PHP Generator to use this template for the selected webpage.

 

The simplest way to create a new template is to modify an existing one (it is much easier than create a new template "from scratch"). Use the table below to select the template corresponding to the necessary state of page and page part. Custom template files should be uploaded to the 'components/templates/custom_templates' directory. This folder should be created by the user of PHP Generator and its content is not changing during the further PHP Generator sessions.

 

The following table shows how to customize common pages used in the generated applications.

 

State of the webpage

Page Part

Default template

Parameters

All Pages

webpage layout

common/layout.tpl

PagePart::Layout

Any PageMode

page list

page_list_menu.tpl
(for top-side menu)

 

page_list_sidebar.tpl
(for sidebar menu)

PagePart::PageList

Any PageMode

 

List page

table grid

list/grid_table.tpl
(for grid view mode)

 

list/grid_card.tpl
(for card view mode)

PagePart::Grid

PageMode::ViewAll

 

single row

list/single_row.tpl
(for grid view mode)

 

list/sinlge_row_card.tpl
(for card view mode)

PagePart::GridRow

PageMode::ViewAll

 

View (separate page)

view/grid.tpl

PagePart::RecordCard

PageMode::View

 

Edit form (editors area)

forms/form.tpl

PagePart::VerticalGrid

PageMode::EditForm

 

Insert form (editors area)

forms/form.tpl

PagePart::VerticalGrid

PageMode::InsertForm

 

Record comparison page

compare/grid.tpl

PagePart::Grid

PageMode::Compare

Edit (separate page)

forms/page_form.tpl

PagePart::VerticalGrid

PageMode::Edit

Insert (separate page)

forms/page_form.tpl

PagePart::VerticalGrid

PageMode::Insert

Edit (modal dialog)

forms/modal_form.tpl

PagePart::VerticalGrid

PageMode::ModalEdit

 

Insert (modal dialog)

forms/modal_form.tpl

PagePart::VerticalGrid

PageMode::ModalInsert

View (modal dialog)

view/record_card_view.tpl

PagePart::VerticalGrid

PageMode::ModalView

Edit (inline form)

forms/inline_form.tpl

PagePart::VerticalGrid

PageMode::InlineEdit

Insert (inline form)

forms/inline_form.tpl

PagePart::VerticalGrid

PageMode::InlineInsert

Print

webpage layout

print/page.tpl

PagePart::PrintLayout PageMode::PrintAll

table grid

print/grid.tpl

PagePart::Grid

PageMode::PrintAll

detail page

print/detail_page.tpl

PagePart::PrintLayout PageMode::PrintDetailPage

Export

data grid

export/pdf_grid.tpl, export/excel_grid.tpl, export/csv_grid.tpl, etc

PagePart::Grid

PageMode::ExportPdf,

PageMode::ExportExcel,

PageMode::ExportCsv,

etc

single record (PDF only)

export/pdf_record.tpl

PagePart::RecordCard

PageMode::ExportPdf

Print Single Record

webpage layout

print/page.tpl

PagePart::PrintLayout PageMode::PrintOneRecord

table grid

view/print_grid.tpl

PagePart::Grid

PageMode::PrintOneRecord

Login page

login_page.tpl

PagePart::LoginPage

Login control

login_control.tpl

PagePart::LoginControl

Home page

home_page.tpl

PagePart::HomePage

Navigation

navigation.tpl

PagePart::Navigation

 

The following table shows how to customize user registration and password recovering pages. These parameters can be used only for the project-level version of this event.

 

Registration Page

registration_page.tpl

PagePart::RegistrationPage

Registration Form

registration_form.tpl

PagePart::RegistrationForm

Password Recovery Page

recovering_password_page.tpl

PagePart::PasswordRecovery

Reset Password Page

reset_password_page.tpl

PagePart::ResetPassword

Resend Verification Email Page

resend_verification_page.tpl

PagePart::ResendVerification

 

The following table shows how to customize emails sent to users on registration and password recovering. These parameters can be used only for the project-level version of this event.

 

Verification email subject

user_verification_subject.tpl

PagePart::Mail

PageMode::MailVerificationSubject

Verification email body

user_verification_body.tpl

PagePart::Mail

PageMode::MailVerificationBody

Password reset email subject

recovering_password_subject.tpl

PagePart::Mail

PageMode::MailRecoveringPasswordSubject

Password reset email body

recovering_password_body.tpl

PagePart::Mail

PageMode::MailRecoveringPasswordBody

 

 

To instruct PHP Generator to use a customized template file for a certain webpage, specify the following code in the page's OnGetCustomTemplate event handler (of course you should replace YourPart and YourMode to the appropriate values from the table above).

 

if ($part == YourPart && $mode == YourMode) {

  $result = 'your_template_file.tpl';

}

 

Example 1:

Suppose we need to use components/templates/custom_templates/staff_edit.tpl file as a template for the edit form of a webpage.

 

if ($part == PagePart::VerticalGrid && $mode == PageMode::Edit) {

  $result = 'staff_edit.tpl';

}

 

Now we can compare the result webpages without using this event and with the enabled one:

 

 

Example 2:

A single event handler can be used to customize multiple templates:

 

if ($part == PagePart::Grid && $mode == PageMode::ViewAll)

   $result = 'games_grid.tpl';

if ($part == PagePart::VerticalGrid && $mode == PageMode::Edit)

   $result = 'games_edit.tpl';  

if ($part == PagePart::RecordCard && $mode == PageMode::View)

   $result = 'games_view.tpl';

 

Example 3

This example shows how to fill a SELECT input with names of all MySQL databases available at the server.

 

1. Specify the OnGetCustomTemplate event handler as follows:

 

// set the template file

if ($part == PagePart::Grid && $mode == PageMode::ViewAll) {

    $result = 'custom_grid.tpl';

 

//  get the list of available databases

    $queryResult = array();

    $this->GetConnection()->ExecQueryToArray('SHOW DATABASES', $queryResult);

 

//  fill a one-dimensional array with database names

    $databaseNames = array();

    foreach($queryResult as $row)

        $databaseNames[] = $row[0];

 

//  assign the parameter in the template

    $params['databaseNames'] = $databaseNames;

}

 

2. Add the following code to the template file:

 

<select name="database">

    {foreach from=$databaseNames item=database}

        <option value="{$database}">{$database}</option>

    {/foreach}

</select>

 

The screen below demonstrates the result output.

 

 

Example 4

This example shows the use of the superglobal $_GET array values in a custom template.

 

1. Specify the OnGetCustomTemplate event handler as follows:

 

if ($part == PagePart::Grid && $mode == PageMode::ViewAll) {

    $result = 'custom_grid.tpl';

 

    // check if the parameter custom_var available

    if (GetApplication()->IsGETValueSet('custom_var'))

      // found

      $params['custom_var'] = GetApplication()->GetGETValue('custom_var');

    else

      // not found. Assign a default value.   

      $params['custom_var'] = '5 (default)';

}

 

2. Add the following code to the template file:

 

<div>

<h4>I am a custom template with a custom variable $custom_var. Its value

  {if !isset($custom_var)}

    still undefined

  {else}

    = {$custom_var}

  {/if}.

</h4>

</div>

 

Example 4

Let's see the login form customization used in our NBA online demo.

 

1. Specify the OnGetCustomTemplate event handler as follows:

 

if ($part == PagePart::LoginPage) {

    $result = 'login_page.tpl';

}

 

2. Add the following code to the template file:

 

<h2>Logins</h2>

<table class="table table-bordered">

  <thead>

    <tr>

         <th>Username</th>

         <th>Password</th>

         <th>Description</th>

    </tr>

  </thead>

  <tbody>

    <tr>

         <td>admin</td>

         <td>admin</td>

         <td>Can modify any record at any page and manage other users.</td>

    </tr>

    <tr>

         <td>lakers</td>

         <td>lakers</td>

         <td>Can modify team info, home games and players for LA Lakers.</td>

    </tr>

    <tr>

         <td>boston</td>

         <td>boston</td>

         <td>The same for the Boston Celtics team.</td>

    </tr>

    <tr>

         <td>game_manager</td>

         <td>game</td>

         <td>Can access only game list. Can modify any game.</td>

    </tr>

  </tbody>

</table>

 

Example 5

The example below is used in our NBA demo application to customize the template used to export a single record to PDF.

 

if ($part == PagePart::RecordCard && $mode == PageMode::ExportPdf) {

    $result = 'game_pdf.tpl';

}

 

Live example can be found here.



Prev Return to chapter overview Next