Article
eZ publish: PHP's Killer App - Parts 1-3
So that you know what they look like, here's the template file faqview.tpl that was used by faqview.php:
<table width="99%" class="nav">
<tr>
<td class="path">:: FAQ View</td>
<td align="right">
<form action="{www_dir}{index}/faq/faqsearch/" method="get">
<input class="searchbox" type="text" name="SearchText" size="10" />
<input class="searchbutton" type="submit" value="{intl-search}" />
</form>
</td>
</tr>
<tr>
<td colspan="2" align="right" class="path">
<form>
{intl-selectcategory}:
<select class="path" onChange="document.location.href='{www_dir}
{index}/faq/faqlist/' + this.options[selectedIndex].value">
<!-- BEGIN category_list_tpl -->
<option value="{category_list_id}" {category_list_selected}>
{category_list_category}</option>
<!-- END category_list_tpl -->
</select>
</form>
</td>
</tr>
</table>
<table width="99%" class="article">
<tr class="articletop">
<td class="articletitle">
<a class="articletitle" href="{www_dir}
{index}/faq/faqlist/{category_id}/">{category}</a> ->
{heading} ()</td>
</tr>
<tr>
<td class="bold">{question}</td>
</tr>
<tr>
<td>{answer}</td>
</tr>
</table>
And the international language file faqview.php.ini...
[strings]
search=Search
selectcategory=Select Category
Now I'm itching to rant again about templates but this time I'll leave it to this comment on PHP and Templates from the creator of XML-RPC Class Server.
To summarize, there are three steps we need to take when we create the files to be included from datasupplier.php:
- Create the file itself, e.g.
faqview.php - Create the template it will read, e.g.
[eZ publish_root]/ezfaq/user/templates/phppoint/faqview.tpl - Create the international language file e.g.
[eZ publish_root]/ezfaq/user/intl/en_GB/faqview.php.ini
The Admin Interface
Moving now to the files we need for the phpPoint administrators, again eZ publish uses a datasupplier.php script, this time stored in [eZ publish_root]/ezfaq/admin/. Here's the data supplier for our eZFaq module:
<?php
// Decides which "event" to perform based on the URL
switch ( $url_array[2] ) {
// Categories
case "categorylist":
include( "ezfaq/admin/categorylist.php" );
break;
case "categorynew":
include ( "ezfaq/admin/categoryedit.php" );
break;
case "categoryedit":
$categoryID=$url_array[3];
include ( "ezfaq/admin/categoryedit.php" );
break;
case "categorydelete":
$categoryID=$url_array[3];
include ( "ezfaq/admin/categorydelete.php" );
break;
// Headings
case "headinglist":
$categoryID=$url_array[3];
include ( "ezfaq/admin/headinglist.php" );
break;
case "headingnew":
$categoryID=$url_array[3];
include ( "ezfaq/admin/headingedit.php" );
break;
case "headingedit":
$categoryID=$url_array[3];
$headingID=$url_array[4];
include ( "ezfaq/admin/headingedit.php" );
break;
case "headingdelete":
$categoryID=$url_array[3];
$headingID=$url_array[4];
include ( "ezfaq/admin/headingdelete.php" );
break;
// FAQs
case "faqlist":
$categoryID=$url_array[3];
$headingID=$url_array[4];
include ( "ezfaq/admin/faqlist.php" );
break;
case "faqnew":
$categoryID=$url_array[3];
$headingID=$url_array[4];
include ( "ezfaq/admin/faqedit.php" );
break;
case "faqedit":
$categoryID=$url_array[3];
$headingID=$url_array[4];
$faqID=$url_array[5];
include ( "ezfaq/admin/faqedit.php" );
break;
case "faqdelete":
$categoryID=$url_array[3];
$headingID=$url_array[4];
$faqID=$url_array[5];
include ( "ezfaq/admin/faqdelete.php" );
break;
case "faqview":
$categoryID=$url_array[3];
$headingID=$url_array[4];
$faqID=$url_array[5];
include ( "ezfaq/admin/faqview.php" );
break;
default:
include( "ezfaq/admin/categorylist.php" );
break;
}
?>
Basically what occurs on the admin side is the same as what happened on the user side. The two things to be aware of on the admin side are:
- When you fire up the ezTemplate class, you'll use the
AdminTemplateDirvariable fromsite.ini. - Also remember that we're using the children from our logic classes to provide the additional "admin logic", for example:
// Instantiate the template class and define
the intl file using site.ini
$tpl = new eZTemplate( "ezfaq/admin/" . $ini->read_var
( "eZFaqMain", "AdminTemplateDir" ),
"ezfaq/admin/" . "intl", $Language,
"categorylist.php" );
$faq = new eZFaqAdmin ();
I'll leave you to digest the rest of the admin and user templates from the ZIP file (you're almost there!).
There are a couple of additional things to be aware of when you create the admin interface.
If you put a gif file called module_icon.gif in [eZ publish_root]/faq/admin/images/, this will be used to display the module icon when you're logged in to the "back end" of eZ publish.
Additionally, you'll find a file [eZ publish_root]/ezfaq/admin/menubox.php in the zip (this appears in every eZ publish module). The file looks like this:
$menuItems = array(
array( "/faq/categorylist/", "{intl-categorylist}" ),
array( "/faq/categorynew/", "{intl-categorynew}" ),
);
?>
The first value is a URI, relative to the eZ publish admin Web root, which eZ publish will send a user to the place to "use" this menu item. The template variables (the second element in the array) appear in the file:
[eZ publish_root]/ezfaq/admin/menubox.php
Such as:
[strings]
module_name=faq
categorylist=Category List
categorynew=New Category
Also note that the first array within $menuItems array will be used by eZ publish as the "default view" for the module -- where an administrator gets sent when they click on the eZFaq icon.