getting_started
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
getting_started [2020/02/12 21:47] – [Inside the instance] sahl | getting_started [2024/02/14 14:16] (current) – sahl | ||
---|---|---|---|
Line 3: | Line 3: | ||
===== Background ===== | ===== Background ===== | ||
- | Platform is a PHP framework. The framework is intended to make development of PHP applications | + | Platform is a fullstack |
- | ===== Architecture | + | The framework is intended to make development |
- | Platform application consist of one or more // | + | ===== Software requirements ===== |
- | ===== Installing platform ===== | + | Platform runs on PHP and requires a MySQL (or compatible) database. It is expected to run on Linux. |
- | Copy the code into your website folder and edit platform_config.php to fit your needs and move it to the parent directory | + | ===== Architecture |
- | <code php> | + | Platform can either be configured as a single-application framework, which then only supports a single application, |
- | $platform_configuration = array( | + | |
- | | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | + | ||
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | Programming something like Facebook would be considered a single application, since every user on the platform is using the same application and interact with each other. Programming something like Confluence, would be done with instances, since each organization should have their own instance of the software, where the data shouldn't be mixed with the data of any other organization. |
- | + | ||
- | + | ||
- | // Mail info | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
- | | + | |
- | // Directories | + | ===== Installing platform ===== |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | + | Copy the code into your website folder and go to the website root. An interactive procedure will guide you through configuring the platform. You will need to have your database credentials ready, and decide where Platform | |
- | // Misc configuration | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | + | ||
- | + | ||
- | // Microbizz | + | |
- | ' | + | |
- | ' | + | |
- | ); | + | |
- | </ | + | |
- | The database user should have full right including rights to create and drop databases as it is expected | + | Platform4PHP will write a configuration file one level up from the web site root, so it need to be able to do so. |
- | Folders should be writable by the web server | + | If you are configuring for instances, then the local database |
- | When finished go to https:// | + | Store folders should be writable for the web user, but doesn' |
- | Now you are ready to start coding! | + | Lastly |
===== Demo example ===== | ===== Demo example ===== | ||
Line 67: | Line 35: | ||
A new instance have now been created with a test user. Observe that a new database is created. You can log out of this instance and into it again. You can also create further instances if you want to, or destroy the instances you have already created. | A new instance have now been created with a test user. Observe that a new database is created. You can log out of this instance and into it again. You can also create further instances if you want to, or destroy the instances you have already created. | ||
- | ==== Creating an instance | + | ===== Where to go next? ===== |
- | We start in ''/ | + | You can start by navigating |
- | <code php [enable_line_numbers=" | + | |
- | <?php | + | |
- | include $_SERVER[' | + | |
- | + | ||
- | \Platform\Design:: | + | |
- | + | ||
- | $new_instance_form = new \Platform\Form(' | + | |
- | + | ||
- | $new_instance_form-> | + | |
- | // Check if instance if taken | + | |
- | if (\Platform\Instance:: | + | |
- | $new_instance_form-> | + | |
- | return false; | + | |
- | } | + | |
- | return true; | + | |
- | }); | + | |
- | + | ||
- | if ($new_instance_form-> | + | |
- | $values = $new_instance_form-> | + | |
- | $instance = \Platform\Instance:: | + | |
- | if ($instance instanceof \Platform\Instance) { | + | |
- | // Instance was created. Login and continue. | + | |
- | $instance-> | + | |
- | $instance-> | + | |
- | $new_instance_form-> | + | |
- | } else { | + | |
- | $new_instance_form-> | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | echo '< | + | |
- | echo '< | + | |
- | echo '</ | + | |
- | + | ||
- | echo '< | + | |
- | $new_instance_form-> | + | |
- | echo '</ | + | |
- | + | ||
- | echo '< | + | |
- | echo ' | + | |
- | echo '</ | + | |
- | + | ||
- | \Platform\Design:: | + | |
- | </ | + | |
- | + | ||
- | Line 4 outputs the start of the page including the starting html-tag, the head-section and the starting body tag. See [[Design class]] for more info. | + | |
- | + | ||
- | In line 6 we create a form to create the instance, which is easily accomplished using the special form file format. In line 8 we add an additional validation function to the form, which check that the name of the instance isn't already used, and triggers an error on the appropriate form field, if this is the case. | + | |
- | + | ||
- | In line 17 we check for a form submission and validates the form. If the form is submitted and is valid, we initializes a new instance in line 19, activate it (22) and performs a login (23). The login will redirect if successful, so we throw an error if this doesn' | + | |
- | + | ||
- | See more in the [[Form class]] and the [[Instance class]]. | + | |
- | + | ||
- | The rest of the page is just layout, with the form being outputted in line 35. | + | |
- | + | ||
- | ==== Logging into the instance ==== | + | |
- | + | ||
- | In the ''/ | + | |
- | + | ||
- | <code php [enable_line_numbers=" | + | |
- | <?php | + | |
- | include $_SERVER[' | + | |
- | + | ||
- | \Platform\Design:: | + | |
- | + | ||
- | $loginform = new \Platform\Form(' | + | |
- | + | ||
- | $loginform-> | + | |
- | // First check if instance exists | + | |
- | $instance = \Platform\Instance:: | + | |
- | if (! $instance ) { | + | |
- | $form-> | + | |
- | return false; | + | |
- | } | + | |
- | // Select the instance to check user credentials. | + | |
- | $instance-> | + | |
- | + | ||
- | $instance-> | + | |
- | + | ||
- | $form-> | + | |
- | return false; | + | |
- | }); | + | |
- | + | ||
- | if ($loginform-> | + | |
- | $loginform-> | + | |
- | } | + | |
- | + | ||
- | echo '< | + | |
- | echo '< | + | |
- | echo '</ | + | |
- | + | ||
- | echo '< | + | |
- | $loginform-> | + | |
- | echo '</ | + | |
- | + | ||
- | echo '< | + | |
- | echo ' | + | |
- | echo '</ | + | |
- | + | ||
- | \Platform\Design:: | + | |
- | </ | + | |
- | + | ||
- | Again we use the [[Form class]] to create a login form and we add a custom validation function. | + | |
- | + | ||
- | We start by checking if the specified instance exists (:10) and if it doesn' | + | |
- | + | ||
- | If we cannot login we trigger an error. | + | |
- | + | ||
- | ==== Inside the instance ==== | + | |
- | + | ||
- | Our application is implemented in ''/ | + | |
- | + | ||
- | <code php [enable_line_numbers=" | + | |
- | <?php | + | |
- | include $_SERVER[' | + | |
- | + | ||
- | Platform\Accesstoken:: | + | |
- | + | ||
- | if ($_GET[' | + | |
- | Platform\Accesstoken:: | + | |
- | Platform\Instance:: | + | |
- | header(' | + | |
- | exit; | + | |
- | } | + | |
- | + | ||
- | if ($_GET[' | + | |
- | $instance = new \Platform\Instance(); | + | |
- | $instance-> | + | |
- | if ($instance-> | + | |
- | $instance-> | + | |
- | } | + | |
- | Platform\Instance:: | + | |
- | header(' | + | |
- | exit; | + | |
- | } | + | |
- | + | ||
- | \Platform\Design:: | + | |
- | + | ||
- | echo '< | + | |
- | echo '< | + | |
- | echo '</ | + | |
- | + | ||
- | echo '< | + | |
- | echo 'You are logged into the system. Your user ID is: ' | + | |
- | echo '</ | + | |
- | + | ||
- | + | ||
- | echo '< | + | |
- | echo '< | + | |
- | echo '< | + | |
- | echo '< | + | |
- | echo '</ | + | |
- | echo '</ | + | |
- | + | ||
- | \Platform\User:: | + | |
- | + | ||
- | echo '< | + | |
- | echo ' | + | |
- | echo '</ | + | |
- | + | ||
- | \Platform\Design:: | + | |
- | </ | + | |
- | + | ||
- | The first thing to do when inside the application, | + | |
- | + | ||
- | After that we check the querystring for two keywords. Logout | + | |
- | + | ||
- | A logout is performed | + | |
- | + | ||
- | Destroying the instance | + | |
- | + | ||
- | We check if the instance was actually stored in the database, and if so: We delete the instance object, which will both remove it from the instance table and drop the entire database containing this instance. This is ofcourse a very dramatic thing to do in a real application and should be accompanied by proper user prompts and warnings. | + | |
- | + | ||
- | After the instance is deleted we deactivate it, to removes traces from it in the session variables and then we redirect back to the start page. | + | |
- | + | ||
- | To show the power and ease of Platform4PHP, | + | |
- | + | ||
- | ===== Where to go next? ===== | + | |
- | The first step in building your own application is to create a subclass of the [[Instance class]] to contain your own objects and logic. The center of Platform | + | Otherwise go to the [[classes]] hierarchy to browse the different platform components or start building your own application. |
Otherwise it is just to explore the other classes in Platform and start coding away. The aim of Platform is to be easy and highly productive, keeping focus on your own ideas while handling all basic things such as database objects, forms, tables and other things as easy and with as little code as possible. | Otherwise it is just to explore the other classes in Platform and start coding away. The aim of Platform is to be easy and highly productive, keeping focus on your own ideas while handling all basic things such as database objects, forms, tables and other things as easy and with as little code as possible. |
getting_started.1581544049.txt.gz · Last modified: 2020/02/12 21:47 by sahl