0

我有两个控制器。它们的第一个路径是controller/news.php,第二个是controller/admin/news.php。我有每个控制器的路线。

对于控制器/管理员/news.php 我有

Route::set('news-admin', 'admin/news(/)', array('start' => '\d+'))
    ->defaults(array(
        'directory' => 'admin',
        'controller' => 'news',
        'action' => 'index',
        'start' => 0,
    ));

对于控制器/news.php:

Route::set('news', 'news(/)', array('start' => '\d+'))
    ->defaults(array(
        'controller' => 'news',
        'action' => 'index',
        'start' => 0,
    ));

当我使用浏览器时,一切正常。当我打电话给

$response = Request::factory('/news')->execute()

在 unittest 中路由,测试运行。但是当我打电话给

$response = Request::factory('admin/news')->execute()

我只收到下一条消息

PHPUnit 3.7.8 by Sebastian Bergmann. 
Configuration read from /home/mydir/Projects/www/kohsite/application/tests/phpunit.xml

经过几次实验,我了解到我无法测试路由包含放置在子文件夹中的控制器的“目录”。

下面我展示了我的 phpunit.xml

<phpunit bootstrap="bootstrap.php" colors="true">
    <testsuite name="ApplicationTestSuite">
      <directory>./classes</directory>
    </testsuite>
    <filter>
        <whitelist>
            <directory suffix=".php">../tests</directory>
            <exclude>
                <directory suffix="*">../cache</directory>
                <directory suffix="*">../config</directory>
                <directory suffix="*">../logs</directory>
                <directory suffix=".php">../views</directory>
                <file>../bootstrap.php</file>
            </exclude>
        </whitelist>
    </filter>
</phpunit>
4

2 回答 2

1

我假设您使用的是 Kohana 3.x?我不确定您是如何设置应用程序的,但是当我设计一个具有管理控制器的站点时,我通常会创建一个不在子文件夹中的管理控制器。默认路由可以处理对http://domain.com/ <controller>/<action>/<id>的任何请求,例如http://domain.com/admin/index

如果我想有一个专门用于管理新闻的控制器,我会创建一个名为“admin”的文件夹,并像这样设置控制器定义:

class Controller_Admin_News extends Controller_Admin {

然后我会在我的 bootstrap.php 中编写一个如下所示的路由:

Route::set('admin_news', 'admin/news(/<action>(/<id>))')
    ->defaults(array(
        'controller' => 'admin_news',
        'action'     => 'index'
    ));

尝试像这样设置您的应用程序,看看它是否有帮助。

于 2012-10-23T05:55:34.320 回答
0

当然,我使用的是 Kohana 3.2。我有控制器

class Controller_Admin_News extends Controller_Admin_Common
于 2012-10-23T12:23:39.870 回答