尊龙凯时人生就是博

laravel·Ö±íµÄʵÏÖµÄ

laravelÊÇÒ»¿îÓÅÒìµÄphp¿ª·¢¿ò¼Ü £¬ËüÔÚʵÏÖorm£¨¹¤¾ß¹ØϵӳÉ䣩²Ù×÷ÖÐÌṩÁËÇ¿Ê¢µÄÖ§³Ö¡£¿ÉÊÇ £¬¹ØÓÚһЩ´óÊý¾ÝÇéÐÎϵÄÓ¦Óà £¬ÎÒÃÇ¿ÉÄÜÐèÒª½«±í¾ÙÐÐÖ§½â £¬ÒÔ±ã¸üºÃµØÖÎÀíÊý¾Ý¡£ÄÇô £¬laravelÔõÑùʵÏÖ·Ö±íÄØ£¿

Ò»¡¢LaravelµÄ·Ö±íÔ­Àí

ÔÚLaravelÖÐ £¬Êý¾ÝÄ£×ӵĻù´¡ÊÇEloquent ORM¡£µ±ÎÒÃÇʹÓÃEloquentµÄÄ£×ÓÀ´»á¼ûÊý¾Ý¿âʱ £¬Laravel½«Æ¾Ö¤Ä£×ÓÃû³ÆÌìÉúÏìÓ¦µÄÊý¾Ý¿â±íÃû¡£ÀýÈç £¬ÎÒÃÇÓÐÒ»¸öÄ£×ÓÀàUser £¬Laravel½«Ä¬ÈÏ»á¼ûÃûΪusersµÄÊý¾Ý¿â±í¡£

ÄÇô £¬·Ö±íµÄÔ­Àí¾ÍºÜ¼òÆÓÁË £¬ÎÒÃÇÖ»ÐèÒªÔÚÄ£×ÓÀàÖнç˵һ¸ö$tableÊôÐÔÀ´Ö¸¶¨±íÃû¼´¿É¡£¹ØÓÚ·Ö±íµÄÇéÐÎ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚÄ£×ÓÀàÖж¯Ì¬ÐÞ¸Ä$tableÊôÐÔÒÔ»á¼û²î±ðµÄ±í¡£

¶þ¡¢LaravelµÄ·Ö±íʵÏÖ

ÏÂÃæ £¬ÎÒÃÇÀ´¿´Ò»ÏÂÔõÑùÔÚLaravelÖÐʵÏÖ·Ö±í¡£

1.ÊÖ¶¯Ð޸ıíÃû

ͨ¹ýEloquent ORM £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÊÖ¶¯ÐÞ¸ÄÄ£×ÓÀàµÄ$tableÊôÐÔÀ´»á¼û²î±ðµÄÊý¾Ý¿â±í¡£

ÀýÈç £¬ÎÒÃÇÓÐÒ»¸öÃûΪOrderµÄÄ£×ÓÀಢÇÒÐèÒª½«¶©µ¥±í·Ö³Éorder_1Óëorder_2Á½ÕÅ±í¡£ÄÇô £¬ÎÒÃÇÖ»ÐèÔÚÄ£×ÓÀàÖнç˵ÈçÏ´úÂ룺

use IlluminateDatabaseEloquentModel;

class Order extends Model
{
    //ÅþÁ¬µ½Ä£×ÓµÄÊý¾Ý±í
    protected $table = 'order_1';
}

µÇ¼ºó¸´ÖÆ

ÕâÑù £¬µ±Äã»á¼û¸ÃÄ£×Óʱ £¬½«»á×Ô¶¯Ö¸Ïòorder_1±í¡£

ÈôÊÇÏëÒª»á¼ûorder_2±í £¬ÎÒÃÇÖ»ÐèÒªÐÞ¸ÄÄ£×ÓÀàµÄ$tableÊôÐÔ¼´¿É¡£

use IlluminateDatabaseEloquentModel;

class Order extends Model
{
    //ÅþÁ¬µ½Ä£×ÓµÄÊý¾Ý±í
    protected $table = 'order_2';
}

µÇ¼ºó¸´ÖÆ

2.×Ô¶¯»¯·Ö±í

ÊÖ¶¯Ð޸ıíÃûËäȻʵÏÖ¼òÆÓ £¬µ«¹ØÓÚ·Ö±íÊýÄ¿¹ý¶àµÄÇéÐÎÏ £¬ÊÖ¶¯ÐÞ¸ÄÒ²±äµÃ·±ËöÇÒÒ×´í¡£Òò´Ë £¬ÎÒÃÇ¿ÉÒÔΪLaravel½¨ÉèÒ»¸ö·Ö±íÀàÀ´×Ô¶¯ÖÎÀí±íÃû¡£

ÔÚLaravelÖÐ £¬ÎÒÃÇ¿ÉÒÔ½¨ÉèÒ»¸öÄ£×Ó¹¤³§ÀàÀ´×Ô¶¯»¯·Ö±í¡£ÀýÈç £¬ÎÒÃÇÓÐÒ»¸öÃûΪOrderµÄÄ£×ÓÀà £¬ÐèÒª½«¶©µ¥±íƾ֤Óû§ID·ÖΪÈô¸É¸öС±í¡£ÎÒÃÇ¿ÉÒÔ½¨ÉèÒ»¸öÃûΪOrderFactoryµÄÄ£×Ó¹¤³§Àà £¬ÓÃÓÚ¶¯Ì¬ÌìÉú±íÃû²¢ÇÒ×Ô¶¯ÖÎÀí±íÃû¡£

use IlluminateSupportFacadesDB;
use IlluminateDatabaseEloquentModel;

class OrderFactory
{
    private $userId;
    private $tableName = 'orders_';

    public function __construct($userId)
    {
        $this->userId = $userId;
        $this->tableName .= $this->getTableName();
    }

    public function makeModel()
    {
        $model = new Model();
        $model->setTable($this->tableName);

        return $model;
    }

    protected function getTableName()
    {
        $tableId = intval($this->userId) % 10 + 1;

        return $tableId;
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚ¹¤³§ÀàÖÐ £¬ÎÒÃÇƾ֤Óû§IDÅÌËã³öÏìÓ¦µÄ±íID £¬ÒÔ±ãÌìÉú׼ȷµÄ±íÃû¡£ÔÚÌìÉúÄ£×Óʱ £¬ÎÒÃÇÖ»ÐèŲÓÃmakeModelÒªÁì¼´¿É¡£

ÀýÈç £¬ÎÒÃÇÐèÒª»ñÈ¡Óû§IDΪ123µÄ¶©µ¥Áбí £¬ÎÒÃÇ¿ÉÒÔÈçÏÂŲÓãº

$factory = new OrderFactory(123);
$order = $factory->makeModel()->get();

µÇ¼ºó¸´ÖÆ

ÕâÑù £¬ÎÒÃǾÍÀֳɵØʵÏÖÁËLaravelÖеķֱí²Ù×÷¡£

Èý¡¢Laravel·Ö±íµÄÓÅÈõµã

ËäÈ»ÔÚijЩÇéÐÎÏ·ֱí¿ÉÒÔ´øÀ´Öî¶àÓÅÊÆ £¬µ«·Ö±íÒ²±£´æһЩÈõµã¡£

1.Óŵã

£¨1£©ÐÔÄÜÌáÉý

µ±Êý¾ÝÁ¿´óʱ £¬·Ö±í¿ÉÒÔ½«±íÖеÄÊý¾ÝÁ¿¼õС £¬´Ó¶øÌá¸ßÅÌÎÊЧÂÊ¡£Í¬Ê± £¬ÓÉÓÚÊý¾Ý·ÖÀà £¬ÎÒÃÇ¿ÉÒÔʹÓøüÓÅÒìµÄË÷Òý·½·¨À´ÓÅ»¯ÅÌÎÊËÙÂÊ¡£

£¨2£©¿ÉÀ©Õ¹ÐÔ

µ±Êý¾ÝÁ¿ÔöÌíµ½¼«ÏÞʱ £¬ÎÒÃÇ¿ÉÒÔʹÓ÷ֱíÀ´À©Õ¹Êý¾Ý¿â £¬´Ó¶øʵÏÖ¸ü¸ßµÄ¿ÉÀ©Õ¹ÐÔ¡£

2.Èõµã

£¨1£©ÆÌÕÅ¿Õ¼ä

·Ö±í»á½«Êý¾ÝÊèÉ¢µ½¶à¸ö±íÖÐ £¬»á´øÀ´Ò»¶¨µÄ¿Õ¼äÆÌÕÅ¡£ÀýÈç £¬ÈôÊÇÎÒÃÇƾ֤Óû§ID·Ö±í¾ÙÐÐÖ§½â £¬¶øij¸öÓû§µÄÊý¾ÝÏà¹ØÓÚÆäËûÓû§À´ËµºÜÉÙ £¬ÄÇôÆäËû·Ö±íÖоͻᱣ´æ´ó×ڵĿÕÖÃÊý¾Ý¡£

£¨2£©ÔöÌí¿ª¾ÙʶÈ

ʹÓ÷ֱí»á½«Êý¾ÝÊèÉ¢µ½¶à¸ö±íÖÐ £¬ÄÇô¹ØÓÚÊý¾Ý±íµÄά»¤»á´øÀ´Ò»¶¨µÄÖØ´óÐÔ¡£Í¬Ê± £¬Ê¹Ó÷ֱíÒ²ÐèÒª¶Ô´úÂë¾ÙÐÐÏìÓ¦µÄÓÅ»¯ £¬ÔöÌíÁË¿ª¾Ùʶȡ£

×ÛÉÏ £¬LaravelµÄ·Ö±íʵÏÖ¹ØÓÚ´óÊý¾ÝÇéÐÎϵÄÓ¦ÓÿÉÒÔ´øÀ´¸ü¸ßµÄÐÔÄܺͿÉÀ©Õ¹ÐÔ £¬¿ÉÊÇÒ²´øÀ´ÁËһЩÖØ´óÐԺͿռäÆÌÕÅÎÊÌâ £¬ÎÒÃÇÔÚʹÓÃʱÐèҪƾ֤ÏêϸÇéÐÎȨºâÀû±×¡£

ÒÔÉϾÍÊÇlaravel·Ö±íµÄʵÏֵĵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

QR code
sitemap¡¢ÍøÕ¾µØͼ