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

ThinkPHP5ÖÐappend()ÒªÁìµÄʹÓÃ

thinkphpÊÇÒ»¿î»ùÓÚphpÓïÑԵĿª·¢¿ò¼Ü¡£ËüÌṩÁ˼òÆÓ¡¢ÓÅÑŵıà³ÌÌåÑéºÍÇ¿Ê¢µÄÀ©Õ¹ÐÔ  £¬³ÉΪÁËphp¿ª·¢ÕßÃǵÄÊ×Ñ¡¿ò¼ÜÖ®Ò»¡£ÔÚthinkphpÖÐ  £¬ÓÐÒ»¸ö·Ç¾­³£ÓõÄÒªÁ졪¡ªappend()¡£±¾ÎĽ«ÏÈÈÝthinkphp5ÖÐappend()ÒªÁìµÄʹÓá£

Ò»¡¢Ê²Ã´ÊÇappend()ÒªÁì

ÔÚThinkPHP5ÖÐ  £¬append()ÒªÁì¿ÉÒÔ×·¼ÓÒ»ÌõÊý¾Ýµ½Model¹¤¾ßÖС£appendÒªÁì¿ÉÒÔÔÚ²»±ØÅÌÎʵ½Ä¿½ñÄ£×Ó¹¤¾ßµÄÊý¾ÝµÄÇéÐÎÏ  £¬¶ÔÆä¹ØÁªµÄÊý¾Ý¾ÙÐÐÐÔÌí¼Ó¡£appendÒªÁìÓï·¨ÈçÏ£º

public function appendRelation($relation, $data = [], $replace = false)

µÇ¼ºó¸´ÖÆ

ÉÏÊöÓï·¨Ú¹ÊÍÈçÏ£º

²ÎÊý ˵Ã÷
$relation ¸Ã²ÎÊýÖ¸¶¨¹ØÁª¹ØϵÃû³Æ
$data ¸Ã²ÎÊýÖ¸¶¨ÒªÔöÌíµÄÊý¾Ý
$replace ¸Ã²ÎÊýÖ¸¶¨ÊÇ·ñÁýÕÖÒѱ£´æ¹ØÁªÊý¾Ý

¶þ¡¢ÔõÑùʹÓÃappend()ÒªÁì

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

ÔÚÏÖʵӦÓÃÖÐ  £¬ÎÒÃǾ­³£ÐèÒªÔÚÒѾ­±£´æµÄ¹ØÁª¹ØϵÖÐÌí¼Óмͼ¡£Õâʱ  £¬ÎÒÃǾͿÉÒÔʹÓÃappend()ÒªÁì¡£ÏÂÃæ  £¬ÎÒÃǼòÆÓÏÈÈÝÒ»ÏÂÔõÑùʹÓá£

Ê×ÏÈ  £¬ÎÒÃÇÐèÒªÔÚÄ£×ÓÖнç˵ºÃËùҪ׷¼ÓµÄ¹ØÁª¹Øϵ  £¬ºÃ±ÈÏÂÃæµÄUserÄ£×ÓÖеÄcity¹ØÁª¹Øϵ£º

class UserModel extends Model
{
    public function city()
    {
        return $this->belongsTo('CityModel');
    }
}

µÇ¼ºó¸´ÖÆ

½ÓÏÂÀ´  £¬ÎÒÃÇÐèҪʵÀý»¯Ò»¸öUser¹¤¾ß£º

$user = UserModel::get(1);

µÇ¼ºó¸´ÖÆ

È»ºóŲÓÃappend()ÒªÁì  £¬ÔöÌícity¹ØÁª¹ØϵµÄ¼Í¼£º

$user->appendRelation('city', [
    'id' => 100,
    'city_name' => '¹ãÖÝ'
]);

µÇ¼ºó¸´ÖÆ

ÖÁ´Ë  £¬ÎÒÃÇÀֳɵØÔÚUserÄ£×ÓµÄcity¹ØÁª¹ØϵÖÐÌí¼ÓÁËмͼ¡£ÈôÊÇÎÒÃǽÓ×ÅÓÖÏëÔöÌíÒ»Ìõ¼Í¼  £¬Ö»ÐèÒªÔÙ´ÎŲÓÃappend()ÒªÁì¼´¿É£º

$user->appendRelation('city', [
    'id' => 101,
    'city_name' => 'ÉîÛÚ'
]);

µÇ¼ºó¸´ÖÆ

Èý¡¢append()ÒªÁì×¢ÖØÊÂÏî

ÔÚʹÓÃappend()ÒªÁìµÄʱ¼ä  £¬ÐèҪעÖØÒÔϼ¸µã£º

append()ÒªÁìÖ»ÊÇ×·¼ÓÒ»ÌõÊý¾Ýµ½¹ØÁª¹ØϵÖÐ  £¬ÈôÒª¸ø¹ØÁª¹ØϵÖеĶà¸ö¼Í¼Ìí¼ÓÊý¾Ý  £¬ÐèҪŲÓöà´Îappend()ÒªÁì¡£

append()ÒªÁì²»»á´¥·¢ÈκÎÊÂÎñ  £¬Ò²²»»á´¥·¢¹ØÁªÊý¾ÝµÄÑéÖ¤¡£

append()ÒªÁìĬÈϲ»»áÁýÕÖÒѱ£´æµÄ¹ØÁªÊý¾Ý  £¬ÈôÊÇÒªÁýÕÖÒѱ£´æµÄ¹ØÁªÊý¾Ý  £¬ÐèÒª½«$replace²ÎÊýÉèΪtrue¡£

ËÄ¡¢×ܽá

±¾ÎÄÏÈÈÝÁËThinkPHP5ÖÐappend()ÒªÁìµÄʹÓá£Í¨¹ýappend()ÒªÁì  £¬ÎÒÃÇ¿ÉÒÔÔÚ²»±ØÅÌÎʵ½Ä¿½ñÄ£×Ó¹¤¾ßµÄÊý¾ÝµÄÇéÐÎÏ  £¬¶ÔÆä¹ØÁªµÄÊý¾Ý¾ÙÐÐÐÔÌí¼Ó¡£ÔÚÏÖʵ¿ª·¢ÖÐ  £¬ÈôÊÇÎÒÃÇÏëÔÚÒÑÓеĹØÁª¹ØϵÖÐÌí¼Óмͼ  £¬ÄÇôappend()ÒªÁìÊDz»¿Éȱ°±ÉÄÒªÁì¡£ÆÚÍû±¾ÎÄÄܹ»×ÊÖúµ½¸÷ÈË£¡

ÒÔÉϾÍÊÇThinkPHP5ÖÐappend()ÒªÁìµÄʹÓõÄÏêϸÄÚÈÝ  £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ