Phalcon7 使用 HMVC

最简单的例子,当然在同一个控制器中使用有没有必要有待商榷。

    <?php

    class HmvcController extends Phalcon\Mvc\Controller
    {

        public function oneAction()
        {
            $this->view->subview = $this->app->request('/hmvc/two');
        }

        public function twoAction()
        {
            $this->view->setVar('action', $this->dispatcher->getActionName());
        }
    }

我们可以根据命名空间实现不同的视图路径以及控制器路径:

$di->set('view', function () use ($config) {
    $view = new View();
    $namespace = $this->get('router')->getNamespaceName();
        $view->setViewsDir(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
    return $view;
});

评论

暂无评论