Reputation: 2503
I'm trying to use form to fill it from database and user can edit information. I add model named "Number" :
Number.php:
<?php
class Model_Number extends Zend_Db_Table_Abstract
{
protected $_name = 'cc_number';
protected $_schema = 'general';
}
In this table (cc_number) , I have three field : "id , number , country"
within application/forms, I add this form:
EditNumber.php:
<?php
Class Form_EditNumber extends Zend_Form
{
public function __construct($option = null)
{
parent::__construct($option);
$this->setName('edit_number');
$message = new Zend_Form_Element_Text('message');
$message->setLabel(' number :')
->setRequired(true);
$country = new Zend_Form_Element_Text('country');
$country->setLabel(' country name :')
->setRequired(true);
$login = new Zend_Form_Element_Submit('login');
$login ->setLabel('edit ');
$this ->addElements(array($message,$login));
$this->setMethod('post');
}
}
In controller , I've tried to get number from last part of URL , and then get information from this number:
Number/editAction:
public function editAction(){
$request = $this->getRequest();
$form_number = new Form_EditNumber();
$uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
$part = basename($uri);
$numberModel = new Model_Number();
$select = $numberModel->fetchRow($numberModel->select()->where("number = '$part'"));
$this->view->edit_form = $form_number->populate($select->toArray());
}
Upvotes: 1
Views: 267
Reputation: 288
I would not get the $part
from the Uri in that way.
It should come from the $_GET
part of the request
Can you print_r
the contents of Zend_Controller_Front::getInstance()->getRequest()
because that way you might get the $part
.
Upvotes: 1
Reputation: 778
To get values from request, use $this->getRequest()->getParam('ParamName');
in controller, where ParamName
is the name of the last param with the number you want.
$part = $this->getRequest()->getParam('ParamName');
Then in the query you need to pass this value like this:
$select = $numberModel->fetchRow($numberModel->select()->where("number = ". $part));
Tip: Its better to use PDO
Upvotes: 0