yii2.0 learning journey (-)

First, install yii2.0 project by composer

* This article is based on that you have installed composer

(1) Jump to the project root directory

cd /xxxx/www

 

(2) download the plug

composer global require "fxp/composer-asset-plugin:~1.1.1"

 

(3) Download yii2

composer create-project --prefer-dist yiisoft/yii2-app-basic basic

* Installation time takes about 30 minutes (due before I had any locally installed version, so many extensions to be installed)

 

Second, familiar yii2.0

(1) project directory

 

(2) the emergence of this page, it said that it has been installed successfully!

The default access path: localhost / basic / web

 

 

(3) create project files tool

** access address /index.php?r=gii**, the tool generates a file by yii

 

 

 

 

* 1 * automatically create controller (c) and view (v) file

 

 

* 2 * automatically create the model file

 

 

 

 

 

 

(3) yii2.0 operating model

* Through the tool creates two files *

 

 

 

 

* 1 * single query data, the frame is built using method

Written by: Model :: findOne (condition)

    / * * 
     * Queries a single data 
     * / 
    public  function actionTest01 () {
         $ WHERE = Array ( 'A_ID' => 14 );
         $ info = FcArticle :: the findOne ( $ WHERE );
         echo '<pre>' ;
         print_r ( $ info ); Die ; 
    }

 

* 2 * add a data frame using a built-in method

Written by:

$ Model = new model addresses ();

$ Model-> field name = value

......

$model->insert();

    / * * 
     * An increased data 
     * @throws \ the Throwable 
     * / 
    public  function actionTest02 () {
         $ article_model = new new FcArticle ();
         $ Time = Time (); 

        $ article_model -> ARTICLE_TITLE = 'test title' ;
         $ article_model -> = author 'Fly' ;
         $ article_model -> type = 0 ;
         $ article_model -> article_content = 'test title' ;
         $ article_model -> article_desc = 'test title' ;
         $ article_model -> is_show = 0 ;
        $article_model->send_time = $time;
        $article_model->sys_add_time = $time;
        $article_model->sys_update_time = $time;
        $result = $article_model->insert();
        echo '<pre>';
        print_r($result);die;
    }

 

* 3 * modify a data frame using a built-in method

    /**
     * 修改单条数据
     * @throws \Throwable
     * @throws \yii\db\StaleObjectException
     */
    public function actionTest03(){
        $where = array('a_id'=>14);
        $article_model = FcArticle::findOne($where);
        $article_model->is_show = 1;
        $article_model->update();
    }

 

* 4 * delete a piece of data, using a built-in method framework

    / * * 
     * Remove a data 
     * / 
    public  function actionTest04 () {
         $ WHERE = Array ( 'A_ID' => 14 ); 
        FcArticle :: the findOne ( $ WHERE ) -> Delete (); 
    }

 

yii2.0 Notes

Before introducing, specially made to contrast with tp5 (company using a tp5)

1, a controller named

tp5: not specified suffix must be added Controller

yii2.0: provisions must write, pour as: TestController

 

2, the method in the controller

tp5: not specified suffix must be added to Action

yii2.0: provisions must write, for example: actionIndex

 

After the words: This is just a brief introduction about the installation and the most basic of additions and deletions to change search yii2.0 operation, like a friend can leave a message if the discussion, next time will

 

Guess you like

Origin www.cnblogs.com/FLy-1992/p/11653160.html