Location: PHPKode > scripts > RogePHP > RoguePHP-0.9.4/RoguePHP-0.9.4/readme.txt
RoguePHP Version 0.9.3


Changes 0.9.3 
  * fixed bug with list index
  * add support for modifiers on list index
  * unit tests for list index

Changes 0.9.2
  * minor bug fixes for corner cases on XhtmlView.php
  * add support for Database Persistence.  https://sourceforge.net/apps/mediawiki/psaghetti/index.php?title=DB

RogePHP is a collection of PHP classes that allow you to perform common web 
functions easily and quickly without all the hasle of setting up other web
frameworks.   Use as much or as little as you like with no need for "Installing"
modifying your include path.  It's designed for high trafic environments with
millions of page views per day.

All RogePHP configuration is done though constants, GLOBAL variables or method
calls.  Copy this directory where you would like to install Rogue to. 
Read config.php for configuration details.  Copy this include to your project
and change the settings as necessary.  You are now ready to go.

I highly recommend the NetBeans IDE.  It has great code completion support.  Be sure
to add your rogue install to your IDE's include path so that you can get code completion.
Code completion will make RoguePHP use very easy.  In NetBeans; go to your project, 
right click, select "properties", select "PHP Include Path", "Add Folder" and add
your RoguePHP directory.  You now have code completion working.

see the sourceforge wiki for more detail.   The DB layer is a single class ~1000 lines.  Very fast with
most features you would want.  Read the code / wiki for more examples.

// execute a sql statment on the master db for SchemaName1 and cache it in APC/Eaccelerator for 900 seconds
$master = true;
// cache the query my name with a global define (let the db layer handle caching for me)
$GLOBALS['CACHED_QUERIES']['example-query'] = array ('local', 900);
// DB maintains a singleton connect to the database.  Get it with this call
$db = DB::getConnection('SchemaName1', $master);
$foo = 'my_value';
$rows = $db->sqlStmt('example-query', "SELECT * FROM table WHERE foo = ?", array($foo));
// rows is an array
// we can also cache it ourselves ($value, $seonds, $key)
LocalCache::getInstance()->set($rows, 900, 'example-query');


If you have used Apache Wicket, the the XhtmlView will be familiar to you.  If
you are more comfortable with JSP or Zend style views, we can do that too.
(see Views.php)

The XhtmlView allows you to build your markup as a stand alone xhtml file.  You
can build it in dreamwaver, vim, emacs, notepad whatever.  Once you have your
markup with sample data, simply apply your rogue namespace attributes on the
markup and let Rogue handle the mapping.  Rogue will compile the pure xhtml
markup into a php file that maps the data into minified xhtml output.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
        <div id="friend_list" rogue:panel="">
            <span>Search Google Contacts:</span><br/>
            <input id="friend_search" name="friend_search" size="20" />
			<!-- render a list of at most 20 friends, default max is 999 -->
            <ol rogue:list="friendList" rogue:max="20" class="SmallText">
                <li><input type="checkbox" rogue:name="friendList.getEmail" /><span rogue:id="friendList.getDisplayName|10"></span></li>

<?xml version="1.0" encoding="UTF-8"?>
<!-- RoguePHP Template Created By: ${user} ${time} -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" 
        <title>RoguePHP View Markup With Sample Data</title>
    <body rogue:panel="body">

VIEW_DIR and VIEW_CACHE_DIR constants need to be defined.  VIEW_CACHE_DIR 
needs to be web writable and can exist anywhere on the FS.  You can also
include views from absolute paths outside of VIEW_DIR.

// the requirements
define('VIEW_DIR', '/path/to/view');
define('VIEW_CACHE_DIR', '/path/to/cache');
require_once '/full/path/to/rogue/views/XhtmlView.php';

// create a new view
$view = new XhtmlView('test/test.xhtml');
// assign data to the view
$view->add('foo', 'bar');
// render will return a string of HTML
echo $view->render();

4.1 View Modifiers
default view modifiers are located in XhtmlParser at the top in the class XmlMods

url: urlencode the parameter
deamp: change "&amp;" to "and", remove ' and &apos;
number: limit the number of characters that will be displayed
upper: uppercase all text
lower: lowercase all text
trim: remove leading and trailing whitespace
pre: prepend some text
post: append some text
cap: upercase the first letter of the first word
allcap: upercase the first letter of all words
ago: run the function timeAgo() on a unixtime stamp to get display time as "x units ago"

add your own view modifiers by calling "XmlMods::addPlugin('name', 'code');".   To create a new plugin

XmlMods::addPLugin('nl_to_br', 'strreplace("\n", "<br />", $v)';

in all cases $v will be the input.  This code will be injected into the compiled view

<a rogue:href="companyList.name|url|deamp|pre:/company/" rogue:id="companyList.name">Big Al's Big Bait Shop</a>

5. Lists:

<ul rogue:list="menu">
<li><a rogue:href="menu.href" rogule:class="menu.class|pre menu" rogue:id="menu.name">

$view->add('menu', array(
array('href' => '#l1', 'class' => 'select', 'name' => 'level 1'),
array('href' => '#l2', 'class' => '', 'name' => 'level 2')


<li><a href="#l1" class="select menu">level 1</a></li>
<li><a href="#l2" class=" menu">level 2</a></li>

6. Conditionals:

<div class="error" rogue:id="errorMsg" rogue:if="errorMsg"><img src='error' /></div>

in this example the containing div and error image are ONLY displayed if the input "errorMsg" is added
to the view variables.  Otherwise, an empty string is printed here.

7. More documentation available on the sourceforge wiki

Return current item: RogePHP