Home >php教程 >PHP开发 >Yii2 framework study notes (1) -- environment construction

Yii2 framework study notes (1) -- environment construction

黄舟
黄舟Original
2016-12-30 09:32:321539browse

I have been learning yii2 framework recently, but learning without thinking is useless. Let’s practice by making a small baby picture display system.

The system functions are as follows:

The front desk section displays uploaded baby pictures and can accept comments/likes.

The background maintains the uploaded photos. You can choose whether the uploaded pictures are public and whether to accept comments.

You can manage comments under your own photos.

There is a task system. The task is to take a few photos of the baby every day and write a description of the number of words. You will get points for completing it.

A points system.

The front-end function is relatively simple and can be completed using jquery/bootstrap that comes with yii2.

The background plan uses adminLTE.

The environment uses the ready-made wamp server (http://www.wampserver.com/en/), and the yii framework uses composer (https://getcomposer.org/).

The advance template of yii2 is used, and the framework is built according to the official documents (https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md )

1. Switch the directory to wamp/apps in cmd and run composer.

[code]composer global require "fxp/composer-asset-plugin:~1.1.1"
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii2

Be careful not to run this command in the wamp/www directory, because placing it in the www directory will expose the entire yii file. In fact, only the two folders frontend/web and backend/web need to be exposed to the user

2. Switch the current directory to wamp/apps/yii2 in cmd and run the initialization command init.bat.

[code]init
Select 0 (development environment)

Yii2 framework study notes (1) -- environment construction


3. Open yii2/common/conf/main-local.php. According to the default configuration inside, create a library named yii2advanced in the local database 4. Run yii migrate

in cmd (the path remains under wamp/apps/yii2). After running, it will help us create the basic table. Good

5. The yii environment built with composer has a problem that the initial path points to the wrong direction, and needs to be modified, otherwise it will not run. The file is \yii2\vendor\yiisoft\yii2\base\Application.php

public function setVendorPath($path)
    {
        $this->_vendorPath = Yii::getAlias($path);
        Yii::setAlias('@vendor', $this->_vendorPath);
        //Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower');
        Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower' . DIRECTORY_SEPARATOR . 'bower-asset');
        Yii::setAlias('@npm', $this->_vendorPath . DIRECTORY_SEPARATOR . 'npm');
    }

The modification point is to point the path of @bower to its lower-level directory bower- in asset.

6. Create a new yii2.conf file under wamp/alias, write the following content and save it, then restart apache

Alias /babytask/admin "e:/wamp/apps/yii2/backend/web/"
Alias /babytask "e:/wamp/apps/yii2/frontend/web/"

<Directory "e:/wamp/apps/yii2/frontend/web/">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride all
   Require all granted
</Directory>

<Directory "e:/wamp/apps/yii2/backend/web/">
   Options Indexes FollowSymLinks MultiViews
   AllowOverride all
   Require all granted
</Directory>

Note:

Because httpd in wamp If the .conf file in alias is configured in .conf, it will be automatically included in the configuration, so as long as this file is written, it will take effect without making other connections.
The Alias ​​in the first two lines in yii2.conf cannot be reversed. If it is written backwards, when the user enters /babytask/admin, apache will first look for things in frontend/web/admin/ instead of backend/web/, resulting in 404.

7. Open the browser, enter localhost/babytask and localhost/babytask/admin, and check whether it can be accessed normally.

The above is the Yii2 framework study notes (1) - the content of environment construction, For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn