url重定向在mvc中。我想将localhost / windshield-replacement.html重定向到localhost / greenvalleyaz

时间:2016-12-20 07:07:51

标签: php url model-view-controller url-routing phalcon-routing

我的应用程序现在是phalcon php框架。我想重定向最后包含.html的网址。为了重定向,我将控制器名称写为WindshieldReplacementHtmlController.php,但由于中间的点,我无法重定向。我该如何解决这个问题?

重定向自:

localhost/windshield-replacement.html

localhost/greenvalleyaz

当我键入localhost/windshield-replacement-html时,它会重定向到目标但是当我使用localhost/windshield-replacement.html时它没有检测到控制器。 这是正确的方法吗?

1 个答案:

答案 0 :(得分:2)

在MVC中,您不应该直接显示View

您必须访问控制器操作 - >在行动中你必须渲染视图

在示例中,我想显示user/order.phtml 我将从浏览器localhost/appname/user/orders

访问此页面

UserController.php

use Phalcon\Mvc\View;

class UserController {

    function ProfileAction(){  //access localhost/appname/controller/profile
    }

    function loginAction(){ //access localhost/appname/controller/profile
    }

    function ordersAction(){ //access localhost/appname/controller/orders

         $view = new View();

         // Setting views directory
         $view->setViewsDir('app/views/');

         $view->start();

         // Shows recent posts view (app/views/user/orders.phtml)
         $view->render('user', 'orders');
         $view->finish();

         // Printing views output
         echo $view->getContent();

    }
}

参考:Phalcon_Mvc_View