problème update et génération form préremplie
Bonjour à tous,
j'ai un problème au niveau de la modification de données.
je m'explique quand je clique sur mon lien, la barre d'adresse contient :
Code:
1 2
|
notice:%20Undefined%20index:%20id%20in%20/var/www/WebMRL/application/views/scripts/configuration/consulterunservice.phtml%20on%20line%2032/WebMRL/public/index.php/configuration/modifierservice |
qui représente cette ligne de code:
Code:
1 2
|
<td><a href="<?php echo $this->url(array('controller'=> 'configuration','action'=>'modifierservice','id'=>$service['id']), null, true); ?>">Modifier</a> |
dans la page, firefox me stipule: L'adresse n'a pas été reconnue,Firefox ne sait pas ouvrir cette adresse car le protocole (notice) n'est associé à aucun programme. Il est peut-être nécessaire d'installer une autre application pour ouvrir ce type d'adresse.
Pourriez vous m'aider à comprendre mon erreur s'il vous plaît pourtant je pensais que ma syntaxe était bonne.
Dans mon controller, j'ai ceci:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
public function modifierserviceAction()
{
try {
$form = new Application_Form_Modifierservice();
$form->setMethod('post');
$this->getRequest()->getParam ( 'id' );
$form->init();
$this->view->formModifierService = $form;
}catch (Zend_Exception $e) {
$this->view->formModifierService = $e->getMessage();
}
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$service = new Application_Model_DbTable_Service();
$this->view->service = $service->searchService($result);
$id = (int)$form->getValue('id');
$row = $service->fetchRow('id='.$id);
$row->name = $form->getValue('name');
$row->link_description = $form->getValue('link_description');
$row->enable = $form->getValue('enable');
$row->updateService($formData);
//$service->ajouterService($formData);
$this->_redirect('/');
} else {
$form->populate($formData);
}
} else {
$id = (int)$this->_request->getParam('id', 0);
if ($id > 0) {
$service = new services();
$services = $service->fetchRow('id='.$id);
$form->populate($services->toArray());
}
}
} |
mon db_table:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
public function searchService($result)
{
$select = $this->select()
->setIntegrityCheck(false)
->from(array('s' => 'service'),
array('id'));
$result = $this->getDbTable()->find($idservice);
if (0 == count($result)) {
return;
}
//initialisation de la variable $row avec l'entrée récupérée
$row = $result->current();
//setting des valeurs dans notre objet $service passé en argument
$service->setIdservice($row->id);
$service->setName($row->name);
$service->setLinkdescription($row->link_description);
$service->setEnable($row->enable);
}
public function updateService($data)
{
$select = $this->select()
->setIntegrityCheck(false)
->from(array('s' => 'service'),
array('id'));
$data = $this->update($select);
} |
et mon formulaire:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
class Application_Form_Modifierservice extends Zend_Form
{
public function init()
{
/* Form Elements & Other Definitions Here ... */
$idservice = new Zend_Form_Element_Hidden('id');
$service = new Zend_Form_Element_Text('name');
//Définition du validateur pour vérifier si le service existe
$validator = new Zend_Validate_Db_NoRecordExists('service', 'name');
if ($validator->isValid($service)) {
// Le nom d'utilisateur semble absent de la table
} else {
// invalide : l'utilisateur est probablement présent dans la table
$messages = $validator->getMessages();
foreach ($messages as $message) {
echo "$message\n";
}
}
$service->setLabel('Service')
->setRequired(true)
->addFilter('StringTrim')
->addValidator($validator)
->addValidator('NotEmpty');
// Définition validateur du textarea limitant max 500 caractères
$validatorarea = new Zend_Validate_StringLength(array('min' => 0,'max' => 500));
if ($validatorarea->isValid("")) {
// retourne true
}else{
echo "Longueur du champ restreint à 500";
}
$description = new Zend_Form_Element_Textarea('link_description');
$description->setLabel('Description')
->setRequired(true)
->addFilter('StringTrim')
->addValidator($validatorarea)
->addValidator('NotEmpty');
//$enable = new Zend_Form_Element_Text('enable');
//$enable->setLabel('Cochez si actif');
$enable = new Zend_Form_Element_Checkbox('enable');
$enable->setLabel('Cochez si actif');
$ajouter = new Zend_Form_Element_Submit('Ajouter');
$ajouter->setAttrib('id', 'ajouter');
$this->addElements(array($idservice,$service,$description,$enable,$ajouter));
}
} |
merci d'avance pour votre aide.
Cordialement,