ÉîÈëÏàʶthinkphp¼ÓÔØcssÎļþµÄÔÀí
ÔÚʹÓÃthinkphp¿ò¼Ü¾ÙÐпª·¢Ê±£¬ÓÐʱ¼ä»áÓöµ½ÎÞ·¨¼ÓÔص½cssÎļþÃûµÄÇéÐΡ£²»µ«»áÓ°ÏìÒ³ÃæµÄ·ºÆðЧ¹û£¬²¢ÇÒ»áÓ°ÏìÍøÕ¾µÄÕûÌåÐÔÄÜ¡£Õë¶ÔÕâÒ»ÎÊÌ⣬ÎÒÃÇÐèÒªÉîÈëÏàʶthinkphp¿ò¼Ü¼ÓÔØcssÎļþµÄÔÀí£¬²¢ÕÆÎÕÓÐÓõĽâ¾öÒªÁì¡£
Ò»¡¢thinkphp¿ò¼Ü¼ÓÔØcssÎļþµÄÔÀí
ÔÚthinkphp¿ò¼ÜÖУ¬ÎÒÃÇÒ»Ñùƽ³£ÊÇͨ¹ýÒýÈëcssÎļþÀ´ÊµÏÖÍøÒ³ÑùʽµÄÉèÖá£Ïêϸ¶øÑÔ£¬ÎÒÃÇͨ³£»áͨ¹ýÒÔÏÂÁ½ÖÖ·½·¨À´¼ÓÔØcssÎļþ£º
ÔÚHTMLÎļþÖÐÊÖ¶¯ÒýÈëcssÎļþ£¬ÈçÏÂËùʾ£º
<link>
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬hrefÊôÐÔÖ¸¶¨ÁËÑùʽ±íÎļþµÄ·¾¶£¬./ÌåÏÖÄ¿½ñĿ¼¡£
ͨ¹ýÔÚPHP¿ØÖÆÆ÷ÖÐŲÓÃViewÊÓͼ¹¤¾ßµÄassignÒªÁ죬½«cssÎļþ·¾¶×ª´ï¸øÇ°¶ËÒ³Ã棬ÈçÏÂËùʾ£º
<?php namespace app\index\controller; use think\Controller; class Index extends Controller { public function index() { $this->assign('css_url','./css/style.css'); return $this->fetch(); } } ?>
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬$this->assignÒªÁìÖеĵÚÒ»¸ö²ÎÊýÖ¸¶¨ÁËÔÚÇ°¶ËÒ³ÃæÖÐʹÓõıäÁ¿Ãû£¬µÚ¶þ¸ö²ÎÊýÖ¸¶¨ÁËcssÎļþµÄ·¾¶£¬$this->fetch()ÒªÁìÓÃÓÚäÖȾÍøÒ³¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¶þ¡¢¿ÉÄܵ¼ÖÂÎÞ·¨¼ÓÔØcssÎļþµÄÔµ¹ÊÔÓÉ
ÔÚʹÓÃthinkphp¿ò¼Ü¼ÓÔØcssÎļþʱ£¬¿ÉÄ᷺ܻÆðÒÔϼ¸ÖÖÇéÐε¼ÖÂÎÞ·¨Õý³£¼ÓÔØcssÎļþ£º
cssÎļþ·¾¶¹ýʧ£ºÔÚHTMLÎļþ»òÕßPHP¿ØÖÆÆ÷ÖÐÖ¸¶¨µÄcssÎļþ·¾¶¹ýʧ»òÕß²»±£´æ£¬»áµ¼ÖÂÎÞ·¨Õý³£¼ÓÔØcssÎļþ¡£
·ÓÉÉèÖÃÎÊÌ⣺ÈôÊÇthinkphp¿ò¼ÜµÄ·ÓÉÉèÖÃÓÐÎ󣬺ñÈûÓн«¶ÔÓ¦µÄURLµØµãÓëÏìÓ¦µÄ¿ØÖÆÆ÷ÒªÁì¶ÔÓ¦ÆðÀ´£¬¾Í¿ÉÄÜ·ºÆðÎÞ·¨¼ÓÔØcssÎļþµÄÕ÷Ïó¡£
¿ò¼Ü°æ±¾¼æÈÝÎÊÌ⣺thinkphp¿ò¼Ü°æ±¾¼æÈÝÎÊÌâÒ²¿ÉÄܵ¼ÖÂÎÞ·¨¼ÓÔØcssÎļþ¡£Õë¶ÔÕâÖÖÇéÐΣ¬ÐèÒªÉîÈëÏàʶ¿ò¼Ü°æ±¾²î±ð£¬²¢¾ÙÐÐÏìÓ¦µÄ°æ±¾¼æÈÝÐÔ´¦Àí¡£
Èý¡¢½â¾öÒªÁì
¼ì²écssÎļþ·¾¶ÊÇ·ñ׼ȷ£ºÕë¶ÔÎÞ·¨¼ÓÔØcssÎļþµÄÇéÐΣ¬ÎÒÃÇ¿ÉÒÔÏȼì²éÒ»ÏÂcssÎļþ·¾¶ÊÇ·ñÓÐÎó£¬È·±£Â·¾¶×¼È·ÎÞÎó¡£
¼ì²é·ÓÉÉèÖÃÊÇ·ñ׼ȷ£ºÔÚʹÓÃthinkphp¿ò¼Üʱ£¬ÎÒÃÇÐèÒªºÜÊÇ×¢ÖØ·ÓÉÉèÖõÄ׼ȷÐÔ£¬È·±£URLµØµãÓëÏìÓ¦µÄ¿ØÖÆÆ÷ÒªÁì¶ÔÓ¦ÆðÀ´¡£
ʹÓÃTP5×Ô´øÒªÁì¼ÓÔØcssÎļþ£ºÔÚ¿ØÖÆÆ÷ÖÐʹÓÃTP5×Ô´øµÄÒªÁì¼ÓÔØcssÎļþ£¬ÒªÁìÈçÏ£º
$this->assign('css_url','/static/css/index.css');
µÇ¼ºó¸´ÖÆ
×¢ÖØÕâÀïµÄ·¾¶ÐèÒªÏêϸµÄƾ֤ÏîÄ¿À´ÉèÖá£
ʹÓþø¶Ô·¾¶¼ÓÔØcssÎļþ£ºÈôÊÇÒÔÉÏÒªÁ춼ÎÞ·¨½â¾öÎÊÌ⣬Ôò¿ÉÒÔ˼Á¿Ê¹Óþø¶Ô·¾¶À´¼ÓÔØcssÎļþ£¬È·±£Äܹ»¼ÓÔص½×¼È·µÄcssÎļþ¡£
×ÜÖ®£¬ÔÚʹÓÃthinkphp¿ò¼Ü¾ÙÐпª·¢Ê±£¬·ºÆðÎÞ·¨¼ÓÔØcssÎļþµÄÇéÐÎÊǷǾ³£¼ûµÄ¡£ÎÒÃÇÐèÒªÕë¶ÔÏêϸÇéÐÎÆÊÎöÎÊÌ⣬ƾ֤²î±ðµÄ½â¾öÒªÁì¾ÙÐд¦Àí¡£Ö»ÓÐÔÚÉîÈëÏàʶ¿ò¼ÜµÄ»úÖÆ£¬²¢ÊìÁ·ÕÆÎÕ½â¾öÎÊÌâµÄ¼¼ÇÉ£¬²Å»ªÕæÕý³ÉΪһÃûÀֳɵĿª·¢Õß¡£
ÒÔÉϾÍÊÇÉîÈëÏàʶthinkphp¼ÓÔØcssÎļþµÄÔÀíµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡