尊龙凯时人生就是博

ThinkPHPÖÐÔõô¾ÙÐÐÇóºÍÅÌËã

ÏàʶThinkPHPµÄÁ½¸ö½¹µã¿´·¨¡ª¡ªÄ£×ӺͿØÖÆÆ÷ÊÇÖ÷ÒªµÄ¡£Ä£×ÓÌåÏÖÓ¦ÓóÌÐòµÄÊý¾ÝÄ£×Ó£¬¿ØÖÆÆ÷ÔòÌåÏÖÓ¦ÓóÌÐòµÄ¿ØÖÆÂß¼­¡£¾ÙÐÐÇóºÍÅÌËãÐèÒªÔÚ¿ØÖÆÆ÷ÒªÁìÖе¼ÈëÏìÓ¦µÄÄ£×Ó²¢Ö´ÐÐÇóºÍ²Ù×÷¡£

ÏêϸÀ´Ëµ£¬ÎÒÃÇ¿ÉÒÔƾ֤ÒÔÏ°취¾ÙÐС£

½¨ÉèÒ»¸öеĿØÖÆÆ÷ÒªÁ죬ÓÃÓÚʵÏÖÇóºÍÅÌËã¡£ºÃ±È£¬ÔÚÏà¹ØµÄ¿ØÖÆÆ÷Öнç˵һ¸öÃûΪsum()µÄÐÂÒªÁì¡£

ÔÚsum()ÒªÁìÖУ¬ÒýÈëÐèÒª¾ÙÐÐÇóºÍÅÌËãµÄÊý¾ÝÄ£×Ó¡£Ò»Ñùƽ³£¶øÑÔ£¬ÎÒÃÇ»áÔÚÄ£×ÓÖÐËÑË÷ÐèÒªÇóºÍµÄÊý¾Ý£¬ÔÙ½«Æä´«¸ø¿ØÖÆÆ÷¾ÙÐÐÅÌËã¡£

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

ÇóºÍÅÌËã´«ÈëÊý¾Ý£¬²¢½«Ð§¹û·µ»Øµ½ÊÓͼÖÐÏÔʾ¡£ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÊý×éµÄ·½·¨·µ»ØÊý¾ÝЧ¹û¡£

ÏÂÃ棬ÎÒÃÇÀ´¿´ÏêϸµÄʵÏÖ¡£

½¨ÉèÒ»¸öеĿØÖÆÆ÷ÒªÁì

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚ¿ØÖÆÆ÷Öнç˵һ¸öеÄÒªÁì¡£ÎÒÃÇ¿ÉÒÔÔÚapp/controller/Ŀ¼Ï½¨ÉèÒ»¸öеĿØÖÆÆ÷Îļþ£¬ºÃ±ÈSum.php£¬È»ºóÔÚÆäÖнç˵һ¸ösum()ÒªÁ죬ÓÃÓÚ¾ÙÐÐÇóºÍÅÌËã¡£

namespace app\controller;

use app\model\DemoModel;

class Sum
{
    public function sum()
    {
        // ÔÚÕâÀï¾ÙÐÐÇóºÍÅÌËã
        return ['result' => $sum];
    }
}

µÇ¼ºó¸´ÖÆ

ÒýÈëÐèÒª¾ÙÐÐÇóºÍÅÌËãµÄÊý¾ÝÄ£×Ó

ÔÚsum()ÒªÁìÖУ¬ÎÒÃÇÐèÒªµ¼ÈëÒªÅÌËã×ܺ͵ÄÊý¾ÝÄ£×Ó¡£Êý¾ÝÄ£×Óͨ³£ÓÃÓÚÅÌÎÊÊý¾Ý¿âÖеÄÊý¾Ý¡£½ç˵ÁËÒ»¸ö½Ð×ö DemoModelµÄÄ£×Ó£¬ÓÃÓÚÅÌÎÊÃûΪ¡°ÕÅÈý¡±µÄÓû§µÄÄêËêÐÅÏ¢¡£

namespace app\model;

use think\Model;

class DemoModel extends Model
{
    protected $table = 'demo';

    public function getAgeByUserName($name)
    {
        return $this->where('name', $name)->value('age');
    }
}

µÇ¼ºó¸´ÖÆ

ÎÒÃÇÔÚ Model ÀàÖнç˵ÁËÒ»¸öÃûΪ getByUserName(age) µÄÒªÁ죬¸ÃÒªÁìÓÃÓÚƾ֤Óû§ÐÕÃû»ñÈ¡ÆäÄêËêÐÅÏ¢¡£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÖ»ÅÌÎÊÐÕÃûΪ¡°ÕÅÈý¡±µÄÓû§µÄÄêËêÐÅÏ¢¡£

¶Ôת´ï½øÀ´µÄÊý¾Ý¾ÙÐÐÇóºÍÅÌËã

µ±ÎÒÃÇÒýÈëÐèÒª¾ÙÐÐÇóºÍÅÌËãµÄÊý¾ÝÄ£×Óʱ£¬¾ÍÄܶÔÊäÈëµÄÊý¾Ý¾ÙÐÐÇóºÍ¡£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÐèÒª¶ÔÅÌÎʳöÀ´µÄÓû§ÄêËêÐÅÏ¢¾ÙÐÐÇóºÍÅÌËã¡£

namespace app\controller;

use app\model\DemoModel;

class Sum
{
    public function sum()
    {
        // ÒýÈëÊý¾ÝÄ£×Ó
        $demoModel = new DemoModel;

        // ÅÌÎÊÕÅÈý¡¢ÀîËÄ¡¢ÍõÎåµÄÄêËêÐÅÏ¢
        $zhangsan = $demoModel->getAgeByUserName('ÕÅÈý');
        $lisi = $demoModel->getAgeByUserName('ÀîËÄ');
        $wangwu = $demoModel->getAgeByUserName('ÍõÎå');

        // ¶ÔÄêËêÐÅÏ¢¾ÙÐÐÇóºÍÅÌËã
        $sum = $zhangsan + $lisi + $wangwu;

        // ·µ»ØÅÌËãЧ¹û
        return ['result' => $sum];
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇʹÓÃÁËDemoModelÄ£×ÓÅÌÎÊÁËÃûΪ¡°ÕÅÈý¡±¡¢¡°ÀîËÄ¡±¡¢¡°ÍõÎ塱µÄÓû§µÄÄêËêÐÅÏ¢£¬²¢¶ÔÆä¾ÙÐÐÇóºÍÅÌËã¡£ÎÒÃÇ×îÖÕ½«ÅÌËãЧ¹û·µ»Ø¸øÁËÊÓͼ²ã¾ÙÐÐչʾ¡£

ÒÔÉϾÍÊÇThinkPHPÖÐÔõô¾ÙÐÐÇóºÍÅÌËãµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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