【问题标题】:Phalcon not rending view action when using router使用路由器时 Phalcon 不呈现视图操作
【发布时间】:2014-03-31 15:39:12
【问题描述】:

我遇到了 Phalcon PHP 的问题。与路由一起使用时无法显示控制器动作的视图

例如:http://vngarena.com/game/kieu-hung-2472.html

结果只是显示了来自 gamedetail action 的文本:“This is gamedetail Action”,而不是视图中的游戏标题。

app/config/routes.php:

$router = new Phalcon\Mvc\Router();
$router->add("/game/([a-z0-9\-]+)-([0-9]+).html", array(
    'namespace' => 'Vokuro\Controllers\\',
    'controller' => 'Frontend',
    'action' => 'gamedetail',
    'slug' => 1,
    'id' => 2
))->setName("game-detail");

/app/controllers/FrontendController.php

use Vokuro\Models\Terms;
use Vokuro\Models\Games;

class FrontendController extends ControllerBase
{

    public function gamedetailAction($slug, $id) {

        echo "This is gamedetail Action";
        $game = Games::findFirstById($id);

        if (!$game) {
            $this->flash->error("Game does not exist");
        }
        else {
            $this->view->game = $game;
            $this->view->screenshots = $game->screenshot;
       }
    }

}

app/views/frontend/gamedetail.volt

{{ game.title }

app/views/layouts/frontend.volt

{{ content() }}

【问题讨论】:

    标签: view routes action phalcon


    【解决方案1】:

    检查事项:

    • 服务器上的视图具有正确的读/写权限
    • 我认为 Phalcon 的命名是区分大小写的。请注意您是如何使用“前端”和“前端”的。

    【讨论】:

    • 太好了!我在路由器配置中将“前端”更改为“前端”,它可以工作。
    • 我只想指出 phalcon Controller/Router 是 case insensetive 而 Volt/View 是 case sensetive匹配模板名称时(作为我的 phalcon 1.3.2 版本)。
    猜你喜欢
    • 2021-10-25
    • 2014-07-21
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 2020-09-03
    • 2012-08-08
    • 1970-01-01
    • 2017-07-31
    相关资源
    最近更新 更多