4

module / Application / config / module.config.php

'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
        ),
        'application' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/application[/:action][/]',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
        ),
    ),
),

私のIndexController.phpには、indexAction()とvalidateAction()があります-(実験するだけで、実際には関数がありません)

私は素晴らしい景色を見ることができます。しかし、私はビューに書き込みます:

echo $this->url('application',array('action' => 'validate'));

そしてそれはただエコーします

/application/

アクションでパスをエコーさせるにはどうすればよいですか?私は考えられるすべてのことを試しましたが、これや同じ問題を抱えている他の人に関する合理的なドキュメントを見つけることができません。

構成のページロード時のvar_dumpは次のとおりです。

array(5) {
["router"]=>
array(1) {
    ["routes"]=>
    array(2) {
    ["home"]=>
    array(2) {
        ["type"]=>
        string(28) "Zend\Mvc\Router\Http\Literal"
        ["options"]=>
        array(2) {
        ["route"]=>
        string(1) "/"
        ["defaults"]=>
        array(2) {
            ["controller"]=>
            string(28) "Application\Controller\Index"
            ["action"]=>
            string(5) "index"
        }
        }
    }
    ["application"]=>
    array(2) {
        ["type"]=>
        string(7) "segment"
        ["options"]=>
        array(2) {
        ["route"]=>
        string(25) "/application[/:action][/]"
        ["defaults"]=>
        array(3) {
            ["__NAMESPACE__"]=>
            string(22) "Application\Controller"
            ["controller"]=>
            string(5) "Index"
            ["action"]=>
            string(5) "index"
        }
        }
    }
    }
}
["service_manager"]=>
array(1) {
    ["factories"]=>
    array(1) {
    ["translator"]=>
    string(45) "Zend\I18n\Translator\TranslatorServiceFactory"
    }
}
["translator"]=>
array(2) {
    ["locale"]=>
    string(5) "en_US"
    ["translation_file_patterns"]=>
    array(1) {
    [0]=>
    array(3) {
        ["type"]=>
        string(7) "gettext"
        ["base_dir"]=>
        string(57) "/home/marshall/html/module/Application/config/../language"
        ["pattern"]=>
        string(5) "%s.mo"
    }
    }
}
["controllers"]=>
array(1) {
    ["invokables"]=>
    array(1) {
    ["Application\Controller\Index"]=>
    string(38) "Application\Controller\IndexController"
    }
}
["view_manager"]=>
array(7) {
    ["display_not_found_reason"]=>
    bool(true)
    ["display_exceptions"]=>
    bool(true)
    ["doctype"]=>
    string(5) "HTML5"
    ["not_found_template"]=>
    string(9) "error/404"
    ["exception_template"]=>
    string(11) "error/index"
    ["template_map"]=>
    array(4) {
    ["layout/layout"]=>
    string(73) "/home/marshall/html/module/Application/config/../view/layout/layout.phtml"
    ["application/index/index"]=>
    string(83) "/home/marshall/html/module/Application/config/../view/application/index/index.phtml"
    ["error/404"]=>
    string(69) "/home/marshall/html/module/Application/config/../view/error/404.phtml"
    ["error/index"]=>
    string(71) "/home/marshall/html/module/Application/config/../view/error/index.phtml"
    }
    ["template_path_stack"]=>
    array(1) {
    [0]=>
    string(53) "/home/marshall/html/module/Application/config/../view"
    }
}
}
4

1 に答える 1

1

ZendSkeletonApplicationから開始している場合、事前定義された「アプリケーション」ルートを Application モジュールの構成から削除しましたか? 最新の ZendSkeletonApplication でこれを複製できる唯一の方法は、ルートが既に定義されている前にアプリケーション ルートを定義することでした。

たとえば、module.config.php の次のルーティング セクションが機能します。

'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),  
            ),  
        ),  
        'application' => array(
            'type' => 'segment',
            'options' => array(
                'route'    => '/application[/:action][/]',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),  
            ),
        ),  
    ),  
)

これを使用すると、動作します:

<?= $this->url('application', array('action' => 'validate')) ?>
// Produces /application/validate/
于 2012-12-22T15:56:36.433 に答える