Open webinar "Creating a Web site on the framework Yii2"


    Last week, our new teacher of the course “Backend Developer in PHP” held the first open lesson on the topic “Creating a Web Site on the Yii2 Framework”. We bring to your attention the recording and transcription of the webinar itself.

    The object-oriented component framework Yii2 is a very popular and useful tool that will come in handy when creating websites. The open lesson of Evgeny Volosatov, which took place on July 2, 2018, was devoted to this topic. As part of an interactive workshop, the teacher not only talked about the features of the framework, but also showed its use in practice.

    Work at an open lesson was held on the principle: "It is better to do once than to see a hundred times." All steps were carried out consistently and according to a previously prepared plan. For a better understanding of the framework, ready-made templates were not loaded. All changes were committed step by step. Feedback was maintained with the audience, so the teacher immediately answered questions and helped to cope with difficulties and mistakes.

    The following tools were used in the online lesson:

    • Open Server;
    • PhpStorm development environment;
    • Git software;
    • Composer application level manager.

    All the necessary software was installed on the PC before starting work.

    In the course of the master class, participants were asked to perform a number of practical tasks together with the teacher:

    1. Preparation of the workplace. The first step is to launch the OS panel from the Open Server folder and configure it (select the special version of Apache-PHP-7 in the “Modules” tab, create a local domain otus.localhost in the “Domains” tab). Next to the address OpenServer / Domains otus folder was created, and in it - the web folder. It was this address that became the root directory of the future site, and the path to it (\ otus \ web) was manually entered in the "Domains" tab. After the server settings were completed, the site was successfully launched and became available in the browser at otus.localhost.
    2. Create the first project file. This procedure, as well as many subsequent ones, was performed via the Open Server console. It contains commands for entering the otus folder (> cd otus), the domains folder (> cd domains) and the web folder. The first index.php file was manually created in the web and a line with simple content, Welcome, was sent.
    3. Installing the Yii2 kernel. The procedure began with updating the version of the Composer package manager via the> composer self-update command and preparing it for work by loading libraries and modules. Also, Git (> git init) was initialized and the created file was connected to it (> git add web \ index php). Next - installing the Yii2 kernel via the command> composer require “yiisoft / yii2: *” As a result, the composer.json and composer.log files appeared in the web folder, plus the vendor folder (it was added to Git exceptions). After that, it was necessary to load PhpStorm and set certain configuration settings and commands in index.php. Also in the otus folder was created a separate folder for the config settings, and in it - the web.php file with the corresponding content.
    4. Creating a developer entry point to manage the program. A Controllers folder was created with a SiteController.php file, the necessary functions and a class with web control inheritance were specified.
    5. Creation of representations (Views). At this stage, a directory with the same name was required, plus an additional folder was created for each controller, and an index.php file for each individual method was created in it. The HTML structure was registered in the main.php file, which was placed in the previously created layouts folder (this helped to avoid the resulting error).
    6. Connecting and configuring the module clearance Bootstrap. The difficult and important stage, the successful implementation of which opened up opportunities for developing beautiful sites without the participation of the designer. To install the module, the command to connect the components was entered into the command line of the panel, after which they were loaded. Also in the main.php file you had to create a php script and connect it to Bootstrap. Next, the NavBar component was called, which is required for navigation. Errors have occurred and to avoid them, the Composer config has been reconfigured in the composer.json file with the correct installation path. After that, it became possible to delete the bower-asset folder in the vendor folder. Also, work was done on setting up the design module (triggers, div-container, etc.) were added to the main.php file.
    7. Creating a menu bar and navigation items Join and Login. Tasks were implemented by inserting the necessary code into main.php. New php files with names corresponding to navigation points (join.php, login.php) were created for the navigation of pages in the site folder. In addition, changes were made to the controller. To “restore order” in the address bar, we had to connect the urlManager component and set the browser request redirection rules in the .htaccess file created for this (web folder).
    8. Connection of the debugging system of the Debug Extension for Yii2 project. For the operation of the system, a special software was downloaded and installed (when it was connected, the steps described in the instructions on the manufacturer's website were performed). As a result of successful completion of this stage, the user was able to see the logs, requests, configuration and other parameters of the site through a special interface panel at the bottom of the page.

    As always, we are waiting for questions, suggestions, comments here or look at the second open lesson .

    Also popular now: