【问题标题】:Want to change phalcon default route想改变phalcon默认路由
【发布时间】:2016-01-19 17:50:46
【问题描述】:

我想更改phalcon中的默认路由,即indexcontroller的索引动作。

我的routes.php

$router = new \Phalcon\Mvc\Router();
//Define a route
$router->add(
    "/",
    array(
        "controller" => "admin", //previously it was "index" 
        "action"     => "index",
    )
);
$router->handle();

现在,当我在浏览器中打开我的网站(例如 http://localhost/test/)时,出现错误:

IndexController handler class cannot be loaded

#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('IndexController...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 C:\wamp\www\test\public\index.php(36): Phalcon\Mvc\Application->handle()
#3 {main}

我很困惑为什么即使在路由文件中替换它之后我的路由仍会转到indexcontroller

【问题讨论】:

  • 可能很傻,但是您是否在不更改类名的情况下复制了文件?
  • 不,事实并非如此。

标签: php phalcon phalcon-routing


【解决方案1】:

设置你需要使用的默认控制器-

$router->setDefaults(array(
   'controller' => 'admin',
   'action' => 'index'  
));

【讨论】:

  • 哇,它的工作。你拯救了我的一天。但是我在之前的项目中从来没有写过这行代码,它仍然可以正常工作。
猜你喜欢
  • 2023-03-30
  • 2012-03-17
  • 1970-01-01
  • 2019-07-21
  • 2017-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多