Reputation: 10046
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?
Upvotes: 0
Views: 468
Reputation: 30721
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
Upvotes: 1