PHsPeed is a low-code, component oriented PHP development environment. Basic functionality can be achieved without a single line of code, but as soon as you need to apply business rules you will have the need to change the default application behavior. In no-code platforms that is difficult, and can result in changing your problem to adapt to the system. In PHsPeed that is not the case. Within ‘events’ you are able to intercept the application flow and change behavior.

What are events?


PHsPeed has a fixed application flow, depending on its application type. For regular PHP applications, PHsPeed will have a minimum of 2 run cycles. In the first cycle the form layout is determined. In the second cycle the data will be sent. Globally it works as follows:


User start the application by entering the url in the browser


Cycle 1


PHsPeed will verify checks to assure security
Will create components and assign values
Build html template and send it to the client

The web browser receives the template and will request for the data by an ajax call

Cycle 2


PHsPeed will verify checks to assure security
Will create components and assign values
Will render the data in JSON and send it to the client


Cycle 3..n


These cycles are depending on the components used that might have their own ajax data requests. 

No matter what cycle, PHsPeed will create the components, at the end of the cycle the components will be freed. That means that each and every component will at least have two events: the onCreate and onDestroy event. 

It is very likely that when you intercept one of these events, you might want to verify the contents of other components. Problem is that you cannot be sure if that component is already created, as it depends on the creation sequence. But in the onCreate, you can set properties of the current component. 


But when can you be sure that the components are all created? Well as soon as all components are created, they all will receive an onActivate event. If you intercept this event withing a certain component, then you can be sure that the component exists and has a value. But….


Suppose that you change the value of a component. It is very well possible that in an earlier stage some business rule needs to be aware of this value, but the event for that component was already fired?

Then there is the onBeforeRender event that comes to the rescue. At this stage all components should have their final values so that you can trust building your application without further issues.

What’s important here is that you are aware of the different states and functions of the events. And that the sequence of events is not guaranteed. If you need to have the final value of a component and request for that value before the event is fired to determine that value then you are in trouble. 


The above might sound overcomplicated, but it isn’t, as long as you keep the following rules in mind:


  1. The onCreate can only be used to set default values of the current component. It will be triggered on Submit and ajax requests.
  2. The onActivate can only be used for values that are retrieved by defaults, session or forms. It will be triggered on Submit and ajax requests. Use it to set values to components, but only apply business rules if you do not need to have the value of other components.
  3. The onBeforeRender should be used to perform processing data. It will only be triggered in an ajax request.


Rendering of a component means that PHsPeed will generate valid dynamic html, javascript (and sometimes css) that will be send to the client. The data rendered will be collected by the form and send in one JSON message to the requesting process.


If you need to apply code in the submit phase or ajax phase then you can verify the state by the standard function isAjax(). It will return true or false.

Components can have events of their own. A database table has events like ‘onBeforeInsert’ and ‘onAfterInsert’. They allow the developer to perform some action just before the insert (i.e. change values) or after the insert (i.e. perform some additional tasks). An important event is the onSubmit and onSubmitBtn that is available on the form and allows the developer to do some actions depending on user input.