phpstructure

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
phpstructure [2019/03/18 11:25]
aducomadmin [Main.php]
phpstructure [2020/06/27 17:27] (current)
aducomadmin [Application flow]
Line 1: Line 1:
 ====== PHsPeed Application structure ====== ====== PHsPeed Application structure ======
  
-If you look at a regular webpage, then, in general, you see a header, a detail, and a footer part. The header and footer are usually pretty standard; the detail part contains your working area and changes all the time.+If you look at a regular website, then, in general, you see a header, a detail, and a footer part; sometimes a sidebar. Mostly, the detail section is where the application runs, the header mostly contains elements like a banner, menu, etc.
  
-The development of a PHsPeed project follows this approach. You can define simple 'blocks' that are reusable in headers and footers and might contain menu for instanceMore advanced blocks could define detail needed in a master-detail relationshipYou can define 'apps('stand-alone applications within a project') alsoThese are the working stones of your projectapps are executable, where modules are PHP classes and not directly executable.+Designing web applications in PHsPeed follows this approach. Reusable elements are defined as 'building blocks' (php classes), details as module that leads to an executable PHP scriptWhile developing your project, you will create/generate lot of PHP filesThe result of this is that you might lose the overview of the PHP application that starts your application. Like in languages like 'cthe main PHP module to start is 'main.php'It is configurableso you can change it to index.php if you prefer. The main application usually contains a login screen that gives access to other modules in your application.
  
-So a project can contain several applications. But in general, there's only one application to start with, for example, a login pageIn PHsPeed project, this is called the 'main' page. If you start another file in your project by entering its URLit will redirect to the main page. By default, it is not allowed to run an application stand-alonewhich is a security measure. If you have more 'main' applications in your project, you must allow them to run stand-alone explicitlyThere's a property in the root component that needs to be set. It is advised to call your initial program 'main.php.' You can set it whatever you like, but if you have many files in directory, it might not be so clear which is the main PHP application to start your application. Of course, if you have set things up correctly, starting any application will lead to the defined main applicationBut if you need an URL for a portal, then it is convenient to have a standard. The only exception to this is when you want to create utility that needs to run within the space of a user applicationI.e., the config application that handles the credentials and connection to the database/email does not have a 'main.php.' It would overwrite the standard main.php which would corrupt your project.+**Note:** //PHsPeed keeps track of your main application and will by default disable direct access to your other PHP modulesIf user is trying to access another module outside of main directlythen the end-user will be redirected to the main application, unless the user is already logged in. For increased security PHsPeed works with tokens to avoid access to other modules outside of main.php. During development and testing, this can be an annoying feature as testing certain module will also direct to the main login pageYou can disable this feature by setting property 'allow to run stand-alone'.//
  
-A PHsPeed application has different parts. If it has a form that is used to generate an //HTML//// template//, you have a PHP file that handles the server side //events//; you have a //JavaScript// file that controls the client-side events, and you have a //CSS// file that handles the layout. In many cases, a lot of these files are generated based upon your //form design// and //properties// that you have set using the //components//.+A PHsPeed module has different parts. If it has a form that is used to generate an //HTML//// template//, you have a PHP file that handles the server-side //events (controller)//; you have a //JavaScript// file that controls the client-side events, and you have a //CSS// file that handles the layout. In many cases, a lot of these files are generated based upon your //form design// that contains //components, //and //properties// that control certain //behavior//. 
 +====== Components and properties ======
  
 +Components can be seen as small lego bricks that have a certain type of functionality that you can use, without the full knowledge of how it's done. There are //non-visual// components, that perform tasks like accessing your database, or creating a pdf document; //visual components// that are visual to the end-user, like an edit field, dropdown, etc//.; and layout components //that format the look and feel of your application. PHsPeed uses the bootstrap grid system for generating your //responsive// layout. More information about the bootstrap grid system can be found [[https://getbootstrap.com/docs/4.1/getting-started/introduction/|here]] and [[https://www.w3schools.com/bootstrap4/bootstrap_grid_system.asp|here]].
  
-===== Main.php =====+===== Application flow of a form application =====
  
-When you create your first application within a new project than by defaulta 'main.php' application is generated and set as the first application to run on your web serverIf you create new module, you can define some default components that PHsPeed creates for youon your design panel. For a standard module that would be a form and a root component, and if you want to create a database-aware applicationa database connector. Don't worry if you have set the wrong options, after generating the module; you can always correct by removing or defining components from the designer.+If the application has been set upthen it is time to generate the codeInitially, you need to generate the code with full deployment of runtime libraries. In later versions of PHsPeed, this is done when you create a projectbut if you look at the provided samples it still might be necessary. Then you can run the module.
  
-**the root component**+PHsPeed will start by executing the main controller application. The controller will 'see' that this is the initial call, and will respond with the form design. The web browser receives this design and will start requesting for additional data. The controller will respond to these requests (in general these are ajax calls) until the form has been build and ready for the end-user.
  
-Other PHP applications that are part in your PHP project are not meant to be called directly from the browser unless you design them to. You can control thisby setting the property 'CanRunStandalone' to true in the 'root' component. The root component is responsible for the basic behavior of the application. By default, this property is set to 'no,' causing a warning on main.php when you generate your application. A project must have at least one runnable application; if that is not the case, PHsPeed will release the defined 'main.php.'+When the end-user hit the submit button or an ajax buttonthen the request is sent to the controller that will perform the appropriate steps to continue.
  
-For each PHP project, there's only one application in control. This application will handle the initial setup, will handle CRUD situations and ajax calls. 
  
-While developing your screen, you will use components that you need to pick from the toolbar. PHsPeed will generate PHP modules (class) for each component you have used. These modules follow an 'autoload' PHP rule. You can have only one class in a PHP file, and the name of the file and PHsPeed will automatically include these classes because of this, so you don't need to use 'include(_once)' to load these. All generated PHP component files contain a class with constructor, destructor and processing code, all inherited from their basic classes in the runtime. There is **no** mixed HTML code in the PHP programs. Instead, the rendering process will retrieve the HTML blocks from (generated) templates, will generate HTML for components depending on properties, modify it where necessary by the __render PHP method and then produce the page. During this process, several events are fired to allow the programmer to intercept in the process and apply your custom code.+===== Application flow and events =====
  
 +Although you can create applications without even programming, at some point you will have the need to interfere with application flow to model the system to your business processes.
  
-===== Application flow =====+During processing and on user actions, PHsPeed will generate //events.  //You can apply your code to these //events.//
  
-PHsPeed applications start in the browser with a multi-step approach. First, PHsPeed will send the basic layout to the browsers. Next, the application will perform Ajax calls to retrieve the physical content, like fields, labels, grid data, etc. This approach has been chosen to make applications more flexible, secure (as Ajax calls can be encrypted) and more easy to debug. PHsPeed generated HTML forms are purely based upon <div>. PHsPeed makes NO use of IFrames.+PHsPeed applications start in the browser with a multi-step approach. First, PHsPeed will send the basic layout to the browsers. Next, the application will perform Ajax calls to retrieve the physical content, like fields, labels, grid data, etc. This approach has been chosen to make applications more flexible, secure (as Ajax calls can be encrypted)and easier to debug. PHsPeed generated HTML forms are purely based upon <div>. PHsPeed makes NO use of IFrames.
  
 Each PHP module that runs will create an application object ($app) and then all designed objects, including building blocks that are embedded in this project. Next, all objects are available for the application to use through the $app object. Each event contains this object as a parameter. It is important to realize that during the constructor phase you should not access other objects as you cannot be sure that they are already created and available. There are two events involved here: first, an **OnCreate** event is fired for each component within the constructor, and when all components are created, an **OnActivate** event for all components is executed. Each PHP module that runs will create an application object ($app) and then all designed objects, including building blocks that are embedded in this project. Next, all objects are available for the application to use through the $app object. Each event contains this object as a parameter. It is important to realize that during the constructor phase you should not access other objects as you cannot be sure that they are already created and available. There are two events involved here: first, an **OnCreate** event is fired for each component within the constructor, and when all components are created, an **OnActivate** event for all components is executed.
Line 32: Line 34:
  
 Each PHP runnable module is by default a control application. It handles initialization, submits and ajax requests. It takes care of session handling, security checks like CSRF, checks if a module can be run stand-alone (not hosted by the main menu), etc. All other modules are PHP classes and cannot run by itself. Each PHP runnable module is by default a control application. It handles initialization, submits and ajax requests. It takes care of session handling, security checks like CSRF, checks if a module can be run stand-alone (not hosted by the main menu), etc. All other modules are PHP classes and cannot run by itself.
 +
  
 ==== Detailed standard application flow ==== ==== Detailed standard application flow ====
  • phpstructure.1552904739.txt.gz
  • Last modified: 2020/02/04 18:28
  • (external edit)