Yii MVC PHP Framework Hello World Content Tutorial

Yii MVC PHP Framework Hello World Content Tutorial

Yii MVC PHP Framework Hello World Content Tutorial

Yesterday, with Yii MVC PHP Framework Hello World Tutorial as shown below, it was a primer tutorial mainly concerned with the setup and installation of a Hello World scenario regarding …

Yii is an open source, object-oriented, component-based MVC PHP web application framework. Yii is pronounced as “Yee” or [ji:] and in Chinese it means “simple and evolutionary” and it can be acronym for “Yes It Is!”.

The MVC stands for Model View Controller … (from Wikipedia again) …

Model–view–controller (MVC) is a software architectural pattern mostly for implementing user interfaces.

… to refresh your mind take a look at , whereas today, we show some early steps with Yii use that use MVC (without the Model) to change the content, and therefore, the appearance of our local MAMP Apache web server’s Hello World website … and you’ll be pleased to know the word “Hello” makes an appearance … no, Lionel.

Along the way we use Apache .htaccess methods making use of mod_rewrite module, which we hope, if you are following this, you are using.

Again, we have to thank the incredible advice on great advice of How to Program with Yii2: Getting Started – Envato Tuts+ Code Tutorial to keep us on the straight and narrow.

So, what do we do today, after yesterday’s installing and configuration with Yii, regarding content?

  1. we change ~/Sites/hello/config/web.php (add into components array) …

    'urlManager' => [
    'showScriptName' => false,
    'enablePrettyUrl' => true
    ],
    … and add a new ~/Sites/hello/web/.htaccess (in the same directory as index.php (of the website)) …

    RewriteEngine on

    # If a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise forward it to index.php
    RewriteRule . index.php
    … via (advice of) Turning on Pretty URLs section of How to Program with Yii2: Getting Started – Envato Tuts+ Code Tutorial
  2. point your web browser at …
    http://localhost:8888/hello/web/site/about
  3. we change ~/Sites/hello/controller/SiteController.php (add in the PHP public function RE: mvC) …

    public function actionSay($target = 'World') {
    return $this->render('say', ['target' => $target]);
    }
    … and add a new ~/Sites/hello/views/site/say.php (RE: mVc) …

    <?php
    use yii\helpers\Html;
    ?>
    <h1>Hello <?= Html::encode($target) ?></h1>
    <p>Welcome to your Yii 2 demonstration application.</p>
    … via (advice of) Building the Say Hello World! Action section of How to Program with Yii2: Getting Started – Envato Tuts+ Code Tutorial
  4. point your web browser at …
    http://localhost:8888/hello/web/site/say?target=Tuts%20Readers

Here’s a slideshow of highlights of yesterday’s (setup and configuration and install) and today’s (content considerations for) a Hello World website created using the Yii 2 MVC PHP framework.


Previous Yii MVC PHP Framework Hello World Tutorial is shown below.

Yii MVC PHP Framework Hello World Primer Tutorial

Yii MVC PHP Framework Hello World Tutorial

Today’s tutorial is a Hello World tutorial for Yii, to quote Wikipedia

Yii is an open source, object-oriented, component-based MVC PHP web application framework. Yii is pronounced as “Yee” or [ji:] and in Chinese it means “simple and evolutionary” and it can be acronym for “Yes It Is!”.

The MVC stands for Model View Controller … (from Wikipedia again) …

Model–view–controller (MVC) is a software architectural pattern mostly for implementing user interfaces.

It makes a fair bit of difference what version you talk about with Yii, and we are talking about Yii 2 today.

You can get up and going with a Hello World level of Yii usage really quickly (especially with the great advice of How to Program with Yii2: Getting Started – Envato Tuts+ Code Tutorial … thanks), and we can say, basically that the major steps for us, integrating it with MAMP (Mac Apache local web server) and a Linux operating system involved …

  1. installing composer, a tool for dependency management in PHP, via …

    curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin
    composer global require "fxp/composer-asset-plugin:~1.1.1"
    composer require yiisoft/yii2
    sudo ln -s /usr/bin/composer.phar /usr/bin/composer

    … that can also be found on the GitHub source repository
  2. composer setup specific to Hello World project …

    cd ~/Sites
    composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
    composer create-project --prefer-dist yiisoft/yii2-app-basic hello

    … in addition we found that we needed to …

    mkdir ~/Sites/hello/vendor/bower/bootstrap
    mkdir ~/Sites/hello/vendor/bower/bootstrap/dist
    mkdir ~/Sites/hello/vendor/bower/jquery
    mkdir ~/Sites/hello/vendor/bower/jquery/dist

  3. create software to help out MAMP via …

    cd /Applications/MAMP/htdocs
    ln -s ~/Sites/hello/ /Applications/MAMP/htdocs/hello

  4. point your web browser at …
    http://localhost:8888/hello/web

You can do great organizational and fast and guaranteed and consistent PHP web work using Yii Framework. Just imagine a CRUD idea you have, and Yii could be a great option for you. Here’s a slideshow of highlights of today’s Hello World website create using the Yii 2 MVC PHP framework.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , , , , , , , , , , , . Bookmark the permalink.

10 Responses to Yii MVC PHP Framework Hello World Content Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *