Yii 2 - จะเปลี่ยนเส้นทางไปยังส่วนหน้าบางหน้าในรูทได้อย่างไรหากถูกบันทึกไว้และเปลี่ยนเส้นทางไปยังหน้าเข้าสู่ระบบส่วนหน้าหากเป็นแขกในรูท

ฉันมีปัญหา. ฉันพยายามใช้ .htaccess ในโฟลเดอร์รูทเพื่อเปลี่ยนเส้นทางดังนี้:

  • localhost/planificacion_talleres/ เปลี่ยนเส้นทางไปยัง localhost/planificacion_talleres/frontend/web/index.php?r=planificacion หากผู้ใช้ถูกบันทึกไว้
  • localhost/planificacion_talleres/ เปลี่ยนเส้นทางไปยัง localhost/planificacion_talleres/frontend/web/index.php?r=site หากผู้ใช้เป็นแขก

แต่ฉันไม่รู้วิธีเปลี่ยนเส้นทางโดยใช้ .htaccess เดียวกันไปยังหน้าอื่นโดยใช้เงื่อนไข ฉันต้องการความช่วยเหลือโปรด


person Felipe Guzman    schedule 24.02.2017    source แหล่งที่มา
comment
คุณต้องการเปลี่ยนเส้นทางโดยใช้ .htaccess หรือไม่   -  person GAMITG    schedule 24.02.2017
comment
ฉันคิดว่านี่เป็นวิธีเดียวที่จะเปลี่ยนเส้นทางจากรูทไปยังเพจ   -  person Felipe Guzman    schedule 24.02.2017


คำตอบ (1)


ฉันคิดว่าเป็นความคิดที่ดีที่จะเปลี่ยนเส้นทางโดยใช้ .htaccess เพราะในกรณีนี้ คุณไม่สามารถจัดการการเปลี่ยนเส้นทางเหล่านี้ได้ ทั้งนี้ขึ้นอยู่กับเงื่อนไขอื่นๆ

ฉันแนะนำให้ใช้การเปลี่ยนเส้นทางแอปพลิเคชัน เช่น:

class DefaultController extends \yii\web\Controller
{

    public function actionIndex()
    {
        $targetRoute = \Yii::$app->user->isGuest
            ? ['site']
            : ['planificacion'];

        return $this->redirect($targetRoute);
    }

}
person IStranger    schedule 24.02.2017
comment
ฉันจำเป็นต้องสร้างคอนโทรลเลอร์นี้ในโฟลเดอร์รูทของโปรเจ็กต์หรือไม่ - person Felipe Guzman; 24.02.2017
comment
ไม่ โปรดดูที่นี่: yiiframework.com/doc-2.0/ guide-index.html#getting-started - person IStranger; 24.02.2017