วันศุกร์ที่ 19 มิถุนายน พ.ศ. 2558

การใช้งาน Yii2 url แบบไม่ต้องมี index.php

1.เปิดใน config->web.php เพิ่ม

'urlManager' => [
    'enablePrettyUrl' => true,    'showScriptName'=>false,// hide index.php    'rules' => [
        'หน้าแรก' => 'site/index',    ]
],
 ในส่วนของ 'components' จะได้ตามรูปล่างนะ

2. เข้าไปที่ folder web จากนั้นก็ สร้างไฟล์ .htaccess แล้วพิมตามโลด

RewriteEngine on # if a directory or a file exists, use it directlyRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.phpRewriteRule . index.php 


 เท่านี้เวลาเราสร้าง controller แล้วเรียก funtion จะเป็นแบบนี้

localhost/webname/web/controllerName/functionName







ไม่มีความคิดเห็น:

แสดงความคิดเห็น