我的Zend Framework路由有什么问题?

时间:2009-08-07 21:56:14

标签: zend-framework

我的ZF有问题,我的代码看起来不错,但是我不能接受参数ID,它返回true,我正在访问网址http://site.com/admin/news/newsedit/1

所以我的代码看起来像这样:

路线

$ad = self::$frontController->getRouter();      
$ad->addRoute('newsedit',
    new Zend_Controller_Router_Route(
        'news/newsedit/:id',
         array(
            'module' => 'admin',
            'controller' => 'news',
            'action' => 'newsedit'
         )
    )
);

动作

public function newseditAction()
{
    /*
        Disable Layout
    */
    $this->_helper->layout->disableLayout();
    /*
        @return : boolen OR string
    */
    $_id = ($this->_getParam('id') !== NULL) ? (int)$this->_getParam('id') : false;

    if ($_id) {
        /*
            @return : array
        */
        $_get = $this->news->select()->where('id = ?', $_id);
        if (count($_get) > 0) {
            $this->view->data = $_get;
        }
    }
    Zend_Debug::dump($this->_getParam('id'));
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

首先检查控制器中是否设置了路径。使用 print_r($this->getFrontController()->getRouter()->getRoutes()); 确认。

如果没有,则表示路由器设置错误。

使用:

$ad = Zend_Controller_Front::getInstance()->getRouter();

代替。

旁注:

 $_get = $this->news->select()->where('id = ?', $_id);

这不会返回任何行。这是Zend_Db_Table_Select对象而不是Zend_Db_Rowset对象。

您需要这样做:

$select = $this->news->select()->where('id = ?', $_id);
$_get = $this->news->fetchAll($select);

甚至更容易:

$_get = $this->news->find($_id)

问候