New example using the Page-View Pattern

Discuss anything that's related to the Raxan framework

New example using the Page-View Pattern

Postby raymond » Wed May 26, 2010 4:56 am

The upcoming RC1 release will not only make it easier to build powerful web applications with the new Page-View Pattern but it will also reduce the amount of code required.

Here's an example from the latest developer snapshot:

Code: Select all
<?php

require_once '../raxan/pdi/autostart.php';

/***
 * @property RaxanPDO $db
 */
class NotesPage extends RaxanWebPage {

    protected $db;
    protected $showRenderTime = true;

    protected function _config() {
        $this->autoAppendViews = true; //'index,form';
        $this->preserveFormContent = true;
        $this->masterTemplate = 'views/notes.html';
        //$this->db = $this->Raxan->connect('sqlite:'.dirname(__FILE__).'/notes.db',null,null,true);    // SQLite DB
        $this->db = $this->Raxan->connect('mysql:host=localhost; dbname=notes','user','password',true); // MySQL DB
    }

    // Views ---

    protected function _indexView() {
        if (!$this->isPostBack) $lst = $this->db->table('notes');
        else  {
            $search ='%'.$this->post->querytxt.'%';
            $lst = $this->db->table('notes','subject like ?',$search);
        }
        $this->noteList->bind($lst,array('altClass'=>'alt'));
    }

    protected function _formView() {
        $id = $this->get->intVal('id');
        if ($id && !$this->isPostBack){
            $data = $this->db->table('notes id,subject,message','id=?',$id);
            $this->form1->inputValues($data[0]);
            $this->title->text('Edit Note');
        }
    }

    protected function _detailsView() {
        $id = $this->get->intVal('id');
        $data = $this->db->table('notes id,subject,message','id=?',$id);
        $this->details->bind($data);
    }

   
    // Events

    protected function deleteNote($e) {
        $this->db->tableDelete('notes','id=?',$e->intVal());
        $this->flashmsg('Record sucessfully removed','bounce','notice');
        $this->redirectTo('notes.php');
    }

    protected function saveNote($e) {
        $id = $this->post->intVal('id');
        $data = $this->post->filterValues('subject,message');

        if (!$id) $rt = $this->db->tableInsert('notes',$data);
        else $rt = $this->db->tableUpdate('notes',$data,'id=?',$id);

        if (!$rt) $this->flashmsg('Error while updating record.');
        else $this->flashmsg('Record sucessfully saved','explode','success close click-cursor');

        $this->redirectTo('notes.php');

    }

}

?>


Here's a screen shot of the Notes example:
notes.png
Notes Screenshot
notes.png (17.18 KiB) Viewed 6894 times


Get the Developer Snapshot here: http://code.google.com/p/raxan/download ... p&can=2&q=
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron