[英]Zend framework edit a record
我正在嘗試在列表頁面中創建編輯記錄功能。 但是我點擊針對記錄的編輯鏈接時遇到以下錯誤。
發生404錯誤找不到頁面。
路由無法匹配請求的URL。 沒有例外
我用於編輯視圖的module.config.php文件代碼是:
'edit' => array(
'type' => 'literal',
'options' => array(
'route' => '/album[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Application\Controller\Album',
'action' => 'edit',
),
),
),
我的相冊列表頁面代碼(用於調用編輯控制器並將ID傳遞給)是:
<a href="<?php echo $this->url('edit',
array('action'=>'edit', 'id' => $album->id));?>">Edit</a>
和editAction代碼是:
$id = (int) $this->params()->fromRoute('id', 0);
請讓我知道我錯過了什么。 我是zend框架的新手。
我認為您必須使用'type' => 'segment'
來查看文檔
<?php
'edit' => array(
'type' => 'segment', /* <--- use segment*/
'options' => array(
'route' => '/album[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Application\Controller\Album',
'action' => 'edit',
),
),
),
關於type
選項的建議是正確的,但是您還需要may_terminate
選項,以確保路由器知道此路由可以匹配 。
'edit' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Application\Controller\Album',
'action' => 'edit',
),
),
'may_terminate' => true, // Add this line
),
現在看到我在module.config.php中的路由腳本是這個。
'album' => array(
'type' => 'literal',
'options' => array(
'route' => '/album/',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Album',
'action' => 'album',
),
),
'may_terminate' => true,
'child_routes' => array(
'add' => array(
'type' => 'Segment',
'options' => array(
'route' => '/album/[:add]',
'constraints' => array(
'add' => '[a-zA-Z0-9_-]+'
),
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Album',
'action' => 'add',
),
),
),
'edit' => array(
'type' => 'Segment',
'options' => array(
'route' => '/album/[:edit][/:id]',
'constraints' => array(
'edit' => '[a-zA-Z0-9_-]+'
),
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Album',
'action' => 'edit',
),
),
),
),
),
在這種情況下,如果我單擊任何鏈接,則僅相冊頁面不顯示我所點擊的其他頁面。
終於我有了解決方案,現在我的應用程序運行正常。
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Application\Controller\Album',
'action' => 'album',
),
),
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.