thinkphpÔõô×öĿ¼
thinkphp ÊÇÒ»ÖÖ»ùÓÚ php ¿ª·¢µÄÆóÒµ¼¶¿ª·¢¿ò¼Ü£¬Ëü¾ßÓпª·¢¿ìËÙ¡¢¸ßЧ¡¢Çå¾²ºÍÎȹ̵ÈÌص㣬ÉîÊÜ¿í´óÆóÒµºÍ¿ª·¢ÕßµÄÈÈ°®ºÍÇàíù¡£ÔÚʹÓà thinkphp ¾ÙÐпª·¢µÄÀú³ÌÖУ¬Ä¿Â¼½á¹¹µÄÉèÖúÍÖÎÀíÊÇÊ®·ÖÒªº¦µÄÒ»²½¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÉîÈë̽ÌÖÔõÑùÔÚ thinkphp ÖÐ×öºÃĿ¼ÖÎÀí¡£
Ò»¡¢ThinkPHP Ŀ¼½á¹¹
ÔÚÏàʶÔõÑù×öºÃĿ¼ÖÎÀí֮ǰ£¬ÏÈÀ´ÏàʶһÏ ThinkPHP µÄĿ¼½á¹¹¡£ThinkPHP µÄĿ¼½á¹¹·ÖΪÈý¸ö²¿·Ö£¬¼´Ó¦ÓÃĿ¼¡¢¸ùĿ¼ºÍÀ©Õ¹Ä¿Â¼¡£
Ó¦ÓÃĿ¼£¨Application£©£ºÓ¦ÓÃĿ¼ÊÇÖ¸ÎÒÃÇÓÃÀ´´æ·ÅÓ¦ÓÃÏà¹ØÎļþµÄĿ¼£¬ºÃ±È¿ØÖÆÆ÷¡¢Ä£×Ó¡¢ÊÓͼµÈ¡£
¸ùĿ¼£¨Public£©£º¸ùĿ¼ÊÇÖ¸´æ·ÅÈë¿ÚÎļþµÈÓëÏîÄ¿ÔËÐÐÏà¹ØµÄÎļþºÍ×ÊÔ´µÄĿ¼£¬ÀýÈç index.php ÎļþºÍһЩͼƬµÈ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
À©Õ¹Ä¿Â¼£¨ThinkPHP£©£ºÀ©Õ¹Ä¿Â¼ÊÇÖ¸´æ·Å ThinkPHP µÄ½¹µã´úÂ룬°üÀ¨¿ØÖÆÆ÷¡¢Ä£×Ó¡¢ÉèÖÃÎļþµÈ¡£
¶þ¡¢ThinkPHP Ŀ¼½á¹¹ÉèÖÃ
1¡¢¸ü¸ÄÏîÄ¿¸ùĿ¼
ÔÚ ThinkPHP µÄĿ¼½á¹¹ÖУ¬ÏîÄ¿¸ùĿ¼µÄÎļþÖü´æÈë¿ÚÎļþ£¬ÀýÈç index.php µÈ¡£ÎªÁ˸üºÃµÄ¶ÔĿ¼¾ÙÐÐÖÎÀí£¬ÎÒÃÇ¿ÉÒÔ½«ÏîÄ¿¸ùĿ¼´ÓĬÈ쵀 Public Ŀ¼¸ü¸ÄΪÆäËû×Ô½ç˵Îļþ¼Ð¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚÏîÄ¿µÄÉèÖÃÎļþ config.php ÖоÙÐÐÉèÖá£
$config = [
// ½«ÏîÄ¿¸ùĿ¼¸ü¸ÄΪ mypublic 'app' => [ 'root_namespace' => [ 'app' => 'application', 'mypublic' => 'public', ], 'root_path' => [ 'application' => __DIR__ . '/../application/', 'public' => __DIR__ . '/../mypublic/', ], ],
µÇ¼ºó¸´ÖÆ
];
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃǽ«ÏîÄ¿¸ùĿ¼´ÓĬÈ쵀 Public Ŀ¼¸ü¸ÄΪ mypublic Ŀ¼¡£ÐèҪעÖصÄÊÇ£¬ÎÒÃÇÒ²ÐèÒªÔÚÏîÄ¿µÄÈë¿ÚÎļþ index.php ÖоÙÐÐÐ޸ģ¬Ð޸ĵÄÒªÁìÈçÏ£º
// ½«ÔÏ鵀 require ¼ÓÈë×Ô½ç˵µÄ mypublic Îļþ¼ÐµÄ·¾¶
//require DIR . ‘/../public/index.php’;
require DIR . ‘/../mypublic/index.php’;
2¡¢ÔöÌíеÄÓ¦ÓÃĿ¼
ÔÚ¾ÙÐÐÏîÄ¿¿ª·¢µÄÀú³ÌÖУ¬ÓÐʱ¼äÐèҪΪһ¸öÏîÄ¿ÔöÌí¶à¸öÓ¦ÓÃĿ¼¡£ºÃ±È˵£¬ÎÒÃÇÐèҪΪ²î±ðµÄÓû§Ìṩ²î±ðµÄ²Ù×÷½çÃ棬¾ÍÐèҪΪ²î±ðµÄÓ¦Óû®·ÖÖ¸¶¨Ò»¸öרÊôµÄĿ¼¡£Õâʱ£¬ÎÒÃÇÐèÒªÔÚÏîÄ¿µÄ application Ŀ¼ÏÂÐÂÔöÒ»¸öеÄÓ¦ÓÃĿ¼£¬²¢¾ÙÐÐÏà¹ØÉèÖá£
½« application Ŀ¼¸´ÖƵ½Ò»¸öÐÂĿ¼ myApplication1 Ï£¬²¢ÔÚ config.php ÖÐÐÂÔöÒ»¸öÓ¦ÓÃĿ¼ÉèÖãº
$config = [
'app' => [ 'pathinfo_depr'=>'-', 'url_html_suffix'=>'html', // µÈ¼ÛÓÚÉèÖÃÎļþÖÐµÄ 'app_namespace' => 'app', 'app_namespace'=>'app', 'auto_bind_module' => true, 'root_namespace' => [ 'app' => 'application', 'public' => 'public', 'myApplication1' => 'application1', //ÐÂÔöÒ»¸öÓ¦ÓÃĿ¼ myApplication1 ], 'root_path' => [ 'application' => __DIR__ . '/../application/', 'public' => __DIR__ . '/../public/', 'myApplication1' => __DIR__ . '/../application1/', //ÐÂÔöµÄ myApplication1 Ŀ¼ ], ],
µÇ¼ºó¸´ÖÆ
];
ÐèҪעÖصÄÊÇ£¬ÔöÌíеÄÓ¦ÓÃĿ¼¿ÉÄÜ»á¶Ô¿ò¼ÜÔËÐб¬·¢Ó°Ï죬ÐèҪעÖØÔÚ²Ù×÷ʱ°ü¹Ü´úÂëµÄ½áʵÐÔ¡£
Èý¡¢ThinkPHP Ŀ¼ÖÎÀí
ÔÚʹÓà ThinkPHP ¾ÙÐпª·¢Ê±£¬Ä¿Â¼ÖÎÀíÊÇÊ®·ÖÒªº¦µÄÒ»²½£¬Ëü¿ÉÒÔ´ó´óÌá¸ß¿ª·¢µÄЧÂʺʹúÂëµÄ¿É¶ÁÐÔ¡£ÔÚ¾ÙÐÐÏîÄ¿¿ª·¢µÄÀú³ÌÖУ¬ÐèҪƾ֤ÏÖÕæÏàÐÎ×öºÃ¸÷¸öĿ¼µÄÉèÖúÍÖÎÀí¡£
1¡¢µ÷½âÓ¦ÓÃĿ¼½á¹¹
ÎÒÃÇ¿ÉÒÔ½«Ó¦ÓÃĿ¼¾ÙÐл®·Ö£¬Ã¿¸öÓ¦ÓÃĿ¼ƾ֤ÏÖʵӪҵ¾ÙÐÐÊèÉ¢£¬ÒÔ±ã¸üºÃµØ¾ÙÐпª·¢ºÍÖÎÀí¡£
ÀýÈ磬¹ØÓÚÒ»¸öµçÉÌÍøÕ¾À´Ëµ£¬¿ÉÒÔ½«Æä»®·ÖΪǰ̨¡¢ºǫ́ºÍÊÖ»ú¶ËÈý¸öÓ¦ÓÃĿ¼£¬¸÷×ÔÓÐ×Ô¼ºµÄ¿ØÖÆÆ÷¡¢ÊÓͼµÈÎļþ¡£ÕâÑùÒ»À´£¬²î±ðÓ¦ÓÃÖ®¼äµÄ´úÂë¾Í²»»á»ìÔÓÔÚÒ»Æð£¬Ò²±ãÓÚ´úÂëµÄµ÷ÊÔ¡¢ÖÎÀíºÍά»¤¡£
2¡¢¶Ô½¹µã´úÂë¾ÙÐл®·Ö
ͨ³£ÇéÐÎÏ£¬ÎÒÃǵĴúÂë»áÉæ¼°Ðí¶àÓªÒµÂß¼£¬ÎªÁËʹµÃ´úÂëÔ½·¢ÇåÎúÒ׶®£¬ÎÒÃÇ¿ÉÒÔ½«´úÂëƾ֤¹¦Ð§¾ÙÐл®·Ö¡£ÀýÈ磬½«¿ØÖÆÆ÷¡¢Ä£×Ó¡¢ÊÓͼ¡¢ÉèÖõÈÎļþƾ֤²î±ðµÄÎļþ¼Ð¾ÙÐзÖÀàÖÎÀí¡£ÕâÑùÒ»À´£¬×ÝÈ»ÊÇÔÚ´úÂëÁ¿ºÜ´óµÄÇéÐÎÏ£¬ÎÒÃÇÒ²Äܹ»ºÜ¿ìµØÕÒµ½ËùÐèÒªµÄ´úÂë¡£
3¡¢¾ÙÐÐͳһµÄÃüÃû¹æ·¶
ÔÚ¾ÙÐÐĿ¼ÖÎÀíʱ£¬ÎÒÃÇ»¹ÐèÒª×ñÕÕͳһµÄÃüÃû¹æ·¶£¬ÒÔ±ãÓÚÔĶÁºÍÖÎÀí¡£ÀýÈ磬¹ØÓÚ¿ØÖÆÆ÷Îļþ£¬¿ÉÒÔƾ֤¹¦Ð§¾ÙÐÐÃüÃû£¬ºÃ±È UserController£¬GoodsController µÈ¡£¹ØÓÚÄ£×ÓÎļþ£¬Ôò¿ÉÒÔʹÓÃÓë¿ØÖÆÆ÷ÏàͬµÄÃüÃû·½·¨£¬ºÃ±È UserModel£¬GoodsModel µÈ¡£
ͬʱ£¬ÔÚ¾ÙÐбäÁ¿¡¢º¯ÊýºÍÀàµÄ½ç˵ʱ£¬Ò²ÐèҪעÖØ×ñÕÕͳһµÄÃüÃû¹æ·¶£¬ÒÔ±ãÓÚ¾ÙÐпçÎļþµÄŲÓúÍʹÓá£
ËÄ¡¢×ܽá
Ŀ¼ÖÎÀíÊÇÒ»¸öÈí¼þ¿ª·¢Àú³ÌÖеÄÖ÷ÒªÊÂÇ飬ËüÄܹ»Ìá¸ßÏîÄ¿´úÂëµÄ¿É¶ÁÐÔ¡¢¿Éά»¤ÐԺͿÉÀ©Õ¹ÐÔ¡£ÔÚʹÓà ThinkPHP ¾ÙÐпª·¢Ê±£¬ÎÒÃÇÐèҪƾ֤ÏÖÕæÏàÐξÙÐÐĿ¼½á¹¹µÄÉèÖã¬Í¬Ê±¾ÙÐÐͳһµÄÃüÃû¹æ·¶ºÍ´úÂëÖÎÀí£¬ÒÔ±ãÓÚ¸üºÃµØ¿ª·¢ºÍÖÎÀíÏîÄ¿¡£
ÒÔÉϾÍÊÇthinkphpÔõô×öĿ¼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡