×ðÁú¿­Ê±¹ÙÍøµÇ¼

ThinkPHP6ÖÐÔõÑùʵÏÖÊý¾Ý¿âǨá㣿

Ëæ×ÅÓ¦ÓóÌÐòÒ»Ö±ÑݽøºÍÐèÇóµÄһֱת±ä£¬ÎÒÃÇÔÚ¿ª·¢Àú³ÌÖо­³£ÐèÒª¶ÔÊý¾Ý¿â¾ÙÐÐÐ޸ġ¢Ç¨áãºÍ¸üР¡£¿ÉÊÇÔÚ¸üÐÂÊý¾Ý¿âµÄÀú³ÌÖУ¬ÈôÊÇδ¾­ÈÏÕæ˼Á¿ºÍά»¤£¬¾Í¿ÉÄ᷺ܻÆðÊý¾Ý³åÍ»¡¢Êý¾ÝɥʧµÈһϵÁÐÎÊÌâ ¡£ÎªÁËÓÐÓõؽâ¾öÕâЩÎÊÌ⣬ÎÒÃÇÐèҪʹÓÃÒ»ÖÖרҵµÄÊý¾Ý¿âǨá㹤¾ßÀ´Íê³ÉÕâЩ²Ù×÷ ¡£

ThinkPHP6ÊÇÒ»¿îÓÃÓÚ¹¹½¨WebÓ¦ÓóÌÐòµÄÊ¢ÐÐPHP¿ò¼Ü£¬ËüÌṩÁËÐí¶àÓÐÓõĹ¦Ð§ºÍ¹¤¾ß£¬ÆäÖаüÀ¨Êý¾Ý¿âǨáã ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚThinkPHP6ÖÐʹÓÃÊý¾Ý¿âǨáãµÄ¹¦Ð§ ¡£

Ò»¡¢Ê²Ã´ÊÇÊý¾Ý¿âǨá㣿

Êý¾Ý¿âǨáãÊÇÖ¸ÔÚÓ¦ÓóÌÐòµÄ¿ª·¢ºÍÔËάÀú³ÌÖУ¬¶ÔÊý¾Ý¿â½á¹¹¾ÙÐиüкÍÐ޸ĵÄÀú³Ì ¡£Ò²¾ÍÊÇ˵£¬Í¨¹ýÊý¾Ý¿âǨá㣬ÎÒÃÇ¿ÉÒÔ¾ÙÐÐÊý¾Ý¿â±íµÄÔöÌí¡¢É¾³ý¡¢ÖØÃüÃûºÍ×ֶεÄÌí¼Ó¡¢Ð޸ġ¢É¾³ýµÈ²Ù×÷ ¡£

ÔÚThinkPHP6ÖУ¬Êý¾Ý¿âǨá㹤¾ßÖ÷Ҫͨ¹ýÁ½¸ö¿´·¨À´ÊµÏÖ£ºÇ¨áãÀàºÍÌî³äÀà ¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

¶þ¡¢ÔõÑùʹÓÃÊý¾Ý¿âǨá㣿

½¨ÉèǨáãÀà

ÔÚThinkPHP6ÖÐʹÓÃÊý¾Ý¿âǨá㣬Ê×ÏÈÐèÒª½¨ÉèÒ»¸öǨáãÀà ¡£Ç¨áãÀàÊÇÒ»¸ö°üÀ¨Á½¸öÒªÁìµÄPHPÀ࣬ÕâÁ½¸öÒªÁì»®·ÖÊÇupÒªÁìºÍdownÒªÁì ¡£

upÒªÁìÓÃÓÚÖ´ÐÐÊý¾Ý¿âǨáã²Ù×÷£¬ÀýÈ罨Éè¡¢Ð޸ġ¢É¾³ýÊý¾Ý¿â±í»ò×Ö¶ÎµÈ ¡£down·½¹æÔòÓÃÓڻعöǨáã²Ù×÷£¬¼´×÷·ÏupÒªÁìÖ´ÐеIJÙ×÷ ¡£

ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀýǨáãÀ࣬ÓÃÓÚ½¨ÉèÒ»¸öÃûΪusersµÄÊý¾Ý¿â±í£º

<?php

use thinkmigrationdbColumn;
use thinkmigrationMigrator;

class CreateUsersTable extends Migrator
{
    public function up()
    {
        $table = $this->table('users', ['engine' => 'InnoDB', 'id' => false, 'primary_key' => 'id']);
        $table->addColumn('id', 'integer', ['signed' => false, 'identity' => true])
            ->addColumn('name', 'string', ['limit' => 32])
            ->addColumn('email', 'string', ['limit' => 128])
            ->addColumn('password', 'string', ['limit' => 60])
            ->addColumn('created_at', 'datetime')
            ->addColumn('updated_at', 'datetime')
            ->create();
    }

    public function down()
    {
        $this->table('users')->drop();
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄǨáãÀàÖУ¬ÎÒÃÇÏÈÔÚupÒªÁìÖн¨ÉèÁËÒ»¸öÃûΪusersµÄÊý¾Ý¿â±í£¬²¢Ìí¼ÓÁËһЩ×ֶΠ¡£È»ºóÔÚdownÒªÁìÖУ¬ÎÒÃÇɾ³ýÁËÕâ¸ö±í ¡£

Ö´ÐÐÊý¾Ý¿âǨáã

½¨ÉèºÃǨáãÀàÖ®ºó£¬ÎÒÃÇÐèҪʹÓÃphp think migrateÏÂÁîÀ´Ö´ÐÐǨáã²Ù×÷ ¡£ÈôÊÇÄ¿½ñ»¹Ã»ÓоÙÐйýÈκÎǨá㣬ÎÒÃÇÐèÒªÏÈʹÓÃphp think migrate:installÏÂÁîÀ´³õʼ»¯Êý¾Ý¿âǨáãµÄÏà¹Ø±í ¡£

½ÓÏÂÀ´£¬ÎÒÃÇ¿ÉÒÔʹÓÃphp think migrate:statusÏÂÁîÀ´Éó²éÄ¿½ñËùÓеÄǨáã״̬ ¡£´Ëʱ£¬ÎÒÃÇ¿ÉÒÔ¿´µ½ÎÒÃǽ¨ÉèµÄǨáãÀ໹δִÐÐ ¡£

È»ºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃphp think migrate:runÏÂÁîÀ´Ö´ÐÐǨáã²Ù×÷ ¡£´Ëʱ£¬ÎÒÃÇ¿ÉÒÔ¿´µ½ÏµÍ³»áÖ´ÐÐÎÒÃÇÊʲŽ¨ÉèµÄǨáãÀ࣬²¢Êä³öһЩµ÷ÊÔÐÅÏ¢ ¡£

Ö´ÐÐÍê±Ïºó£¬ÎÒÃÇ¿ÉÒÔÔÙ´ÎʹÓÃphp think migrate:statusÏÂÁîÀ´Éó²éÄ¿½ñËùÓеÄǨáã״̬ ¡£´Ëʱ£¬ÎÒÃÇÓ¦¸Ã¿ÉÒÔ¿´µ½ÎÒÃǽ¨ÉèµÄǨáãÀàÒѾ­Ö´ÐÐÀֳɣ¬Êý¾Ý¿âÖÐÒѾ­½¨ÉèÁËÃûΪusersµÄ±í ¡£

ÈôÊÇÎÒÃÇÐèÒª»Ø¹öÊʲŽ¨ÉèµÄǨá㣬¿ÉÒÔʹÓÃphp think migrate:rollbackÏÂÁî ¡£Õâ¸öÏÂÁî»á»Ø¹ö×îºóÒ»´ÎÖ´ÐеÄǨáã²Ù×÷ ¡£

ÁíÍ⣬ÎÒÃÇ»¹¿ÉÒÔʹÓÃphp think migrate:resetÏÂÁîÍù·µ¹öËùÓÐÒѾ­Ö´ÐеÄǨáã²Ù×÷ ¡£

Èý¡¢ÔõÑùʹÓÃÌî³äÀࣿ

³ýÁËǨáãÀ࣬ThinkPHP6»¹ÌṩÁËÒ»ÖÖ³ÆΪÌî³äÀàµÄ¹¦Ð§ ¡£Ìî³äÀàÓÃÓÚÏòÒѾ­±£´æµÄÊý¾Ý¿â±íÖÐÌí¼Ó²âÊÔÊý¾Ý»òĬÈÏÊý¾Ý ¡£

ÓëǨáãÀàÀàËÆ£¬Ìî³äÀàÒ²ÊÇÒ»¸ö°üÀ¨Á½¸öÒªÁìµÄPHPÀ࣬ÕâÁ½¸öÒªÁì»®·ÖÊÇupÒªÁìºÍdownÒªÁì ¡£

ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀýÌî³äÀ࣬ÓÃÓÚÏòÃûΪusersµÄÊý¾Ý¿â±íÖÐÌí¼ÓһЩ²âÊÔÊý¾Ý£º

<?php

use thinkmigrationSeed;

class AddTestUsers extends Seed
{
    public function run()
    {
        $data = [
            [
                'name' => 'ÕÅÈý',
                'email' => 'zhangsan@test.com',
                'password' => password_hash('123456', PASSWORD_DEFAULT),
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => 'ÀîËÄ',
                'email' => 'lisi@test.com',
                'password' => password_hash('123456', PASSWORD_DEFAULT),
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => 'ÍõÎå',
                'email' => 'wangwu@test.com',
                'password' => password_hash('123456', PASSWORD_DEFAULT),
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s'),
            ],
        ];

        $this->table('users')->insert($data)->save();
    }

    public function down()
    {
        $this->execute('TRUNCATE TABLE users;');
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄÌî³äÀàÖУ¬ÎÒÃÇÔÚupÒªÁìÖÐʹÓÃinsertÒªÁìÏòÊý¾Ý¿â±íÖÐÌí¼ÓÁËÈýÌõ²âÊÔÊý¾Ý ¡£È»ºóÔÚdownÒªÁìÖУ¬ÎÒÃÇʹÓÃexecuteÒªÁìɾ³ýÁËÕâÈýÌõ²âÊÔÊý¾Ý ¡£

Ö´ÐÐÌî³äÀàµÄÒªÁìÓëÖ´ÐÐǨáãÀàµÄÒªÁìÀàËÆ£¬ÎÒÃÇ¿ÉÒÔʹÓÃphp think seed:runÏÂÁîÖ´ÐÐÌî³äÀàµÄupÒªÁì ¡£ÈôÊÇÐèÒª»Ø¹öÌî³äÀàµÄʹÃü£¬¿ÉÒÔʹÓÃphp think seed:rollbackÏÂÁî ¡£

ËÄ¡¢×ܽá

±¾ÎÄÏÈÈÝÁËÔÚThinkPHP6ÖÐʹÓÃÊý¾Ý¿âǨáãºÍÌî³äµÄÒªÁ죬²¢ÇÒͨ¹ýʾÀý´úÂëÑÝʾÁËÔõÑù½¨ÉèǨáãÀàºÍÌî³äÀ࣬ÒÔ¼°ÔõÑùÖ´ÐкͻعöǨáãºÍÌî³ä²Ù×÷ ¡£ÈôÊÇÄãÕýÔÚ¿ª·¢ºÍά»¤Ò»¸öÓ¦ÓóÌÐò£¬²¢ÇÒÐèÒª¶ÔÊý¾Ý¿â¾ÙÐÐÐ޸ĺ͸üУ¬ÇëÒ»¶¨Ê¹ÓÃÕâÖÖרҵµÄÊý¾Ý¿âǨá㹤¾ß£¬ÒÔ°ü¹ÜÄãµÄÊý¾ÝÇå¾²ºÍ׼ȷÐÔ ¡£

ÒÔÉϾÍÊÇThinkPHP6ÖÐÔõÑùʵÏÖÊý¾Ý¿âǨá㣿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼ ¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý ¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ