SartajPHP ( PHP Framework )


App Object Events

App Object Events

Page Class is parent class of every SartajPHP Application. This gives event oriented structure to develop an application. There are different type of events which is occurred on different time.

Global App(module) Example to handle page events:-

  • Page New Request Event:-

New Event of page class is occurred when a new request is received by an application. It is start of request to that application. If application has new event handler then the application process that code only. You can check the new event of application and change the output to browser.

if(SphpBase::page()->isnew){

echo "this is simple module type new event handler";

}

  • Page Submit Event:- When a HTML form or form component submit to application then this event is fire. You can handle this event with in module by check the flag of event.

    if(SphpBase::page()->issubmit){

    echo "this is simple module type submit event handler";

    }

  • Page Insert Event:- When a form component submit to application with empty record then this event will occurred. It makes easy to build database binding application. Mostly this event uses for insert a record in database. You can handle this event with in module by check the flag of event.

    if(SphpBase::page()->isinsert){

    echo "this is simple module type insert event handler";

    }

  • Page Update Event:- When a form component submit to application with track record id for database then this event will occurred. It makes easy to build database binding application. Mostly this event uses for Update a record in database.You can handle this event with in module by check the flag of event.

    if(SphpBase::page()->isupdate){

    echo "this is simple module type update event handler";

    }

  • Page Delete Event:- When a hyperlink or URL with track record id for database then this event will occurred. It makes easy to build database binding application. Mostly this event uses for delete a record in database. You can handle this event with in module by check the flag of event.

    if(SphpBase::page()->isdelete){

    echo "this is simple module type delete event handler";

    }

  • Page View Event:- When a hyperlink or URL with track record id for database then this event will occurred. It makes easy to build database binding application. Mostly this event uses for fetch a record from database. The Form Component Automatically bind all components to database. You can handle this event with in module by check the flag of event.

    if(SphpBase::page()->isview){

    echo "this is simple module type view event handler";

    }

  • Page User Event:- When a hyperlink or URL with event arguments pass to an application then this event will occurred. You can create your own events and event handlers with the help of this event handler. You can handle this event with in module by check the flag of event.

    if(SphpBase::page()->isevent){

    echo "this is simple module type user event handler for " . SphpBase::page()->getEvent() ;

    }

Basic App Example to handle page events:-

class index extends \Sphp\tools\BasicApp{

    private $temp1 = null;

// Application life cycle events with in sequence

    public function onstart(){

        echo "app start";

    }

    public function ontempinit($temp){

        echo " when temp file initialize";

    }

    public function ontempprocess($temp){

        echo "tempfile process";

    }

    public function onready(){

        echo "temp file processed with all components";

    }

    public function page_new(){

       echo "you open in browser " . getThisURL();

    }

    public function page_submit(){

       echo "you submit form to " . getThisURL() ;

    }

    public function onrun($temp){

        echo "app run";

    }

    public function onrender($temp){

        echo "app ready to render";

    }  



// Application Database handling events

    public function page_insert(){

       echo "you open in browser " . getThisURL() . " and form submit to " .  getThisURL() . " url";

    }

    public function page_update(){

       echo "you open in browser " . getEventURL("view",1) . " and edited form submit to " .  getThisURL() . " url";

    }

    public function page_delete(){

       echo "you open in browser " . getEventURL("delete",1) . " to delete record in table where id=1 " ;

       //$this->dbEngine->executeQueryQuick("SELECT FROM tbl1 WHERE id=1");

    }

    public function page_view(){

        // fill all components of form automatically from database and send to browser

        $this->page->viewData($this->temp1->getComponent('form2'));
        $this->setTempFile($this->temp1);

    }

// Application life custom events 

    // $evtp == event parameter, myevent1 == any event name you want to handle

    public function page_event_myevent1($evtp){
      //open url = getEventURL("myevent1")
    }

    public function page_event_myevent2($evtp){
      //open url = getEventURL("myevent2")

    }

 }