views:

209

answers:

1

I have a problem with ZF, my code looks OK, but I can't take the parameter ID, it return true, and i'm accesing the url right http://site.com/admin/news/newsedit/1

So my code looks like this:

Route

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

Action

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'));
}

What I'm doing wrong?

+1  A: 

Hi,

Try the following:

First check if the routes are set in your controller. Use print_r($this->getFrontController()->getRouter()->getRoutes()); to confirm.

If not, you are setting the router in the wrong instance.

Use:

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

instead.

on a sidenote:

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

this doesnt return any rows. this is a Zend_Db_Table_Select object not an Zend_Db_Rowset Object.

You would need to do:

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

or even easier:

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

greetings

Rufinus
Hmm, your solution doesn't work for me :(.Could be this a problem: /* News pagination ADMINE SIDE */ $ad->addRoute( 'admin_news', new Zend_Controller_Router_Route('news/:page', array('module' => 'admin','controller' => 'news', 'action' => 'index')) ); /* News edit */ $ad->addRoute( 'newsedit', new Zend_Controller_Router_Route('news/newsedit/:id', array('module' => 'admin','controller' => 'news', 'action' => 'newsedit')) );
Uffo
hmm you can't see the code right like this, try here http://pastebin.com/m71b2ce6b
Uffo
what i dont understand is, why you do this in the first place, only to save you /id/ ?eg. your url: http://site.com/admin/news/newsedit/1 Normal URL: http://site.com/admin/news/newsedit/id/1try to switch the position of the routes you postet. i guess if you define news/:page this would be true for news/newsedit to. (newsedit would be page)
Rufinus
Yeah, that worked thx man!
Uffo