oui j'allais oublié, j'utilise le $_name
oui j'allais oublié, j'utilise le $_name
Tout a fait, le setIntegrityCheck est dans des cas précis, principalement lors de jointure.
Je te renvoi à cette discussion => Doit-on utiliser setIntegrityCheck
Pour les insertions / suppressions :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 $tab = array( 'un_nom_de_colonne' => $variableDeCetteColone, 'un_nom_de_colonne2' => $variableDeCetteColone2, ... ); $this->insert($tab);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 $tab = array( 'un_nom_de_colonne' => $variableDeCetteColone, 'un_nom_de_colonne2' => $variableDeCetteColone2, ... ); $this->update($tab, 'id_annonce=' . $id_annonce);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 $this->delete('id_annonce=' . $id_annonce);
c'est super bien expliqué.
Je fais mes liens de table et je te tiens au courant ? j'ai du taff mdr
c'est possible d'avoir ton mail si possible ( en message privé) stp enfin si tu veux
j'ai l'impression que c'est plus lisible comme code.
mais cela peut planter même si j'ai pas encore créer les autres models?
Normalement oui, puisque ton SGBD doit avoir ses propres règles de vérification quand il y a des relations.
Je vais déco, bonne nuit
ok ca roule merci pour tout, je m'occupe de créer tous mes modèles ce soir.
bonne nuit.
en commentant ton code et en ayant fait tous les models avec les foreign keys, j'ai encore une application error.
j'ai modifié la requête que tu m'avais envoyé
comment je peux faire pour afficher chacun des champ dans mes td stp?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public function lireTout(){ $select = $this->select() ->setIntegrityCheck(false) ->from(array('s' => 'service'), array('name','link_description','enable')); $result = $this->fetchAll($select); return $result->toArray(); }
merci d'avance.
ah ca c'est bon
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 $service['name'];
Bonjour,
j'ai un petit soucis d'insertion.
Puis je avoir un peu d'aide s'il vous plaît?
j'ai l'erreur suivante :
Catchable fatal error: Object of class Application_Model_DbTable_Service could not be converted to string in /usr/local/zend/share/ZendFramework/library/Zend/Db/Statement/Pdo.php on line 228
Voici mon Db_table :
et mon controller:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 protected $_name = 'service'; protected $_primary = 'id'; // genre id_**** protected $_dependentTables = array('Deviceservice'); public function lireTout(){ $select = $this->select() ->setIntegrityCheck(false) ->from(array('s' => 'service'), array('name','link_description','enable')); $result = $this->fetchAll($select); return $result->toArray(); } public function ajouterService($service, $description, $enable) { $data = array( 'name' => $service, 'link_description' => $description, 'enable' => $enable, ); $this->insert($data); }
La clé primaire de service est transmise à la table device_service:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 $model = new Application_Model_DbTable_Service(); $this->view->service = $model->ajouterService();
merci d'avance de votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 protected $_name = 'device_service'; protected $_primary = 'id'; protected $_referenceMap = array( 'Reporter' => array( 'columns' => 'id', 'refTableClass' => 'Service', 'refColumns' => 'id' ) ); protected $_referenceMap = array( 'Reporter' => array( 'columns' => 'id', 'refTableClass' => 'Device', 'refColumns' => 'id' ) );
Cordialement,
autant pour moi, je me suis trompé d'action dans le controller :
En remettant cela au bon endroit:
j'ai une erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 $model = new Application_Model_DbTable_Service(); $this->view->service = $model->ajouterService();
arning: Missing argument 1 for Application_Model_DbTable_Service::ajouterService(), called in /var/www/WebMRL/application/controllers/ConfigurationController.php on line 90 and defined in /var/www/WebMRL/application/models/DbTable/Service.php on line 23 Warning: Missing argument 2 for Application_Model_DbTable_Service::ajouterService(), called in /var/www/WebMRL/application/controllers/ConfigurationController.php on line 90 and defined in /var/www/WebMRL/application/models/DbTable/Service.php on line 23 Warning: Missing argument 3 for Application_Model_DbTable_Service::ajouterService(), called in /var/www/WebMRL/application/controllers/ConfigurationController.php on line 90 and defined in /var/www/WebMRL/application/models/DbTable/Service.php on line 23 Notice: Undefined variable: service in /var/www/WebMRL/application/models/DbTable/Service.php on line 26 Notice: Undefined variable: description in /var/www/WebMRL/application/models/DbTable/Service.php on line 27 Notice: Undefined variable: enable in /var/www/WebMRL/application/models/DbTable/Service.php on line 28
merci d'avance de votre aide.
Cordialement,
en remettant mon formulaire :
j'ai l'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public function ajouterserviceAction() { // action body Zend_Layout::getMvcInstance()->setLayout('layoutajoutserv'); $form = new Application_Form_Ajoutservice(); $form->envoyer->setLabel('Ajouter'); $this->view->form = $form; if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $service = $form->getValue('name'); $description = $form->getValue('link_description'); $enable = $form->getValue('enable'); $service = new Application_Model_DbTable_Service(); $service->ajouterService($service,$description,$enable); $this->_redirect('/'); } else { $form->populate($formData); } } }
atchable fatal error: Object of class Application_Model_DbTable_Service could not be converted to string in /usr/local/zend/share/ZendFramework/library/Zend/Db/Statement/Pdo.php on line 228
pourriez vous m'aider s'il vous plaît, merci d'avance.
re bonjour,
j'ai corrigé certaines choses.
Mon problème est que j'insers des valeurs NULL.
Pourriez vous me donne run coup de main s'il vous plaît ?
Mon formulaire:
mon controller :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 class Application_Form_Ajoutservice extends Zend_Form { public function init() { /* Form Elements & Other Definitions Here ... */ $id = new Zend_Form_Element_Hidden('id'); $service = new Zend_Form_Element_Text('name'); $service->setLabel('Service') ->setRequired(true) ->addFilter('StringTrim') ->addValidator('NotEmpty'); $description = new Zend_Form_Element_Text('link_description'); $description->setLabel('Description') ->setRequired(true) ->addFilter('StringTrim') ->addValidator('NotEmpty'); $enable = new Zend_Form_Element_Checkbox('enable'); $enable->setLabel('Cochez si actif'); $envoyer = new Zend_Form_Element_Submit('envoyer'); $envoyer->setAttrib('id', 'boutonenvoyer'); $this->addElements(array($id,$service,$description,$enable,$envoyer)); } }
mon model :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public function ajouterserviceAction() { // action body Zend_Layout::getMvcInstance()->setLayout('layoutajoutserv'); $form = new Application_Form_Ajoutservice(); $form->setAction('http://6.0.0.40/WebMRL/public/index.php/configuration/consulterunservice') ->setMethod('post'); $form->envoyer->setLabel('Ajouter'); $this->view->form = $form; if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { $service = $form->getValue('name'); $description = $form->getValue('link_description'); $enable = $form->getValue('enable'); $service = new Application_Model_DbTable_Service(); $service->ajouterService($service,$description,$enable); $this->_redirect('/'); } else { $form->populate($formData); } } }
merci d'avance de votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 public function ajouterService($service,$description,$enable) { $data = array( 'name' => $service, 'link_description' => $description, 'enable' => $enable, ); $this->insert($data); }
Cordialement,
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager