Salut a tous,

voila mon souci, je veux faire une simple update de ma base en passant par un formulaire, j'ai écris un code qui marchait il y'a quelques jours mais j'ai fait des modifs, résultat çà ne fonctionne plus. Mon gros souci est que je n'ai aucun retour d' erreur ?!
Pourtant mon environnement n'a pas changé. Plus précisément, lorsque je soumet le formulaire il semble bien le traiter et me renvoit "formulaire valide" (voir le code, normalement tout s'est bien passé), mais la base n'est pourtant pas modifiée. Il ne semble y avoir aucun problème avec l'acquisition de la table et le tableau de donnée transmit parait ok :/
bref j'y suis depuis ce matin et j'y comprend rien.

J'ai essayé d'épurer le code au maximum pour le post, j'espere que vous pourrez m'eclairer ! (ps: l'action new-course marche tres bien, seul l'edit-course ne marche pas).

la table :
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- phpMyAdmin SQL Dump
-- version 3.1.1
-- http://www.phpmyadmin.net
--
-- Serveur: localhost
-- Généré le : Ven 27 Février 2009 à 17:49
-- Version du serveur: 5.1.30
-- Version de PHP: 5.2.8
 
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
 
--
-- Base de données: `courses_platform`
--
 
-- --------------------------------------------------------
 
--
-- Structure de la table `courses`
--
 
CREATE TABLE IF NOT EXISTS `courses` (
  `c_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `c_title_raw` varchar(80) NOT NULL,
  `c_title_formatted` varchar(80) DEFAULT NULL,
  `c_description` varchar(255) NOT NULL,
  `c_creator_id` int(11) unsigned DEFAULT NULL,
  `c_creation_date` datetime DEFAULT NULL,
  `c_editor_id` int(11) unsigned DEFAULT NULL,
  `c_edit_date` datetime DEFAULT NULL,
  `c_edit_comment` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`c_id`),
  UNIQUE KEY `c_title_raw` (`c_title_raw`,`c_title_formatted`,`c_description`),
  UNIQUE KEY `c_title_formatted` (`c_title_formatted`),
  KEY `c_creator_id` (`c_creator_id`),
  KEY `c_editor_id` (`c_editor_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
 
--
-- Contraintes pour les tables exportées
--
 
--
-- Contraintes pour la table `courses`
--
ALTER TABLE `courses`
  ADD CONSTRAINT `courses_ibfk_5` FOREIGN KEY (`c_creator_id`) REFERENCES `users` (`u_id`) ON DELETE NO ACTION ON UPDATE CASCADE,
  ADD CONSTRAINT `courses_ibfk_6` FOREIGN KEY (`c_editor_id`) REFERENCES `users` (`u_id`) ON DELETE NO ACTION ON UPDATE CASCADE;
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
 
/**
 * CoursesController
 * 
 * application/default/controllers/CourseController.php
 */
 
// indexAction() : get the array of courses
// listlessonsAction() : get the array of lessons
// viewlessonAction() : get the right lesson
// _getModel() : build and get a Model_Table to allow the requests above
 
 
require_once 'Zend/Controller/Action.php';
 
class CoursesController extends Zend_Controller_Action 
{
	protected $_model;
 
	/**
     * indexAction()
     * list the courses
     *
     * @return void
     */
	public function indexAction() 
	{
	...
	}
 
	...
 
	/**
     * newCourseAction() 
     * create a course
     *
     * @return void
     */
	public function newCourseAction() 
	{
        $this->_applyForm('Course', 'new-course');
	}
 
	...
 
	/**
     * editCourseAction() 
     * edit a course
     *
     * @return void
     */
	public function editCourseAction() 
	{
		$courseId = $this->_request->getParam('c_id');
		$model = $this->_getModel();
	    $courses = $model->fetchEntries('Courses', 'c_id', $courseId);
 
	    print_r($courses);
 
	    $registry = Zend_Registry::getInstance(); 
	    $registry->set('courses', $courses);
	    $url = $this->view->url(array(  'controller' => 'courses',
	    								'action' => 'edit-course',
	                                    'c_id' => $courseId,
	                            ),
	                            'default', true);
	    $apply = $this->_applyForm('Course', $url, 'c_id', $courseId);
	    /*if($apply){
	        $archivesCourse['ac_course_id']    = $courses['0']['c_id'];
	        $archivesCourse['ac_title']        = $courses['0']['c_title_raw'];
	        $archivesCourse['ac_description']  = $courses['0']['c_description'];
	        $archivesCourse['ac_editor_id']    = $courses['0']['c_editor_id'];
	        $archivesCourse['ac_edit_date']    = $courses['0']['c_edit_date'];
	        $archivesCourse['ac_edit_comment'] = $courses['0']['c_edit_comment'];
	        $model->save($archivesCourse, 'ArchivesCourses');
	    }*/
	    unset($registry['courses']);
	}
 
	/**
     * _getModel() 
     * get a new Table instance
     *
     * @return void
     */
    protected function _getModel()
    {
        if (null === $this->_model) {
            require_once APPLICATION_PATH . '\models\Table.php';
            $this->_model = new Model_Table();
        }
        return $this->_model;
    }
 
    /**
     * function _applyForm()
     * create and get back the appropriate Form_ object
     * if isPost, insert or, if $row and $rowvalue are provided, update datas
     *
     * @param  string $table_name_with_cap
     * @param  string $actionTarget
     * @param  mixed  $row
     * @param  mixed  $rowValue	 
	 * @return bool $updating
     */
	protected function _applyForm($form_name_with_cap, $actionTarget, $row = '', $rowValue = '')
	{
        $request = $this->getRequest();
        $form = 'Form_' . $form_name_with_cap;
        $form = new $form(array(
        						'action' => $actionTarget,
								'method' => 'post'));
        $updating = false;
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($request->getPost())) {
                if($row != '' && count($row) == count($rowValue)){
                    $model = $this->_getModel();
                    $formValues = $form->getValues();
                    $model->upToDate($formValues, $form_name_with_cap . 's', $row, $rowValue);
                    //debug
                    echo '$formValues : ';
                    print_r($formValues);
                    echo '$form_name_with_cap : ' . $form_name_with_cap;
                    echo 'formulaire valide';
                    $updating = true;
                }
                else if(count($row) != count($rowValue)){
                    throw new Exception('Cannot update entries, not the same amount of rows and values');
                }
                else if ($row == ''){
                    $model = $this->_getModel();
                    $formValues = $form->getValues();
                    $model->save($formValues, $form_name_with_cap.'s');
                    //debug
                    //echo '$formValues : ';
                    //print_r($formValues);
                    //echo '$table_name_with_cap1 : ' . $table_name_with_cap;
                    echo 'formulaire valide2';
                }
            }
            else{
                echo 'formulaire non valide';
                //debug
                print_r($form->getErrors());
                print_r($form->getMessages());
            }
        }
        else {
            echo 'formulaire non posté';
        }
        $this->view->form = $form;
        return $updating; 
	}
}
?>
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
 
/**
 * Model_Table
 * 
 * @author
 * @version 0.01
 * 
 * application/default/models/Table.php
 */
 
// Standard methods for all the tables
 
 
/**
 * half of the business logic (other side is under the DbTable folder)
 */
 
class Model_Table
{
    /** Model_Table_Support */
    protected $_table;
 
    /**
     * get a named table object
     * 
     * @param  string $table_name_with_cap
     * @return Model_Guestbook_Table
     */
    public function getTable($table_name_with_cap)
    {
        unset($this->_table);
        require_once APPLICATION_PATH . '/models/DbTable/'.$table_name_with_cap.'.php';
        $modelDbTableName = 'Model_DbTable_'.$table_name_with_cap;
        $this->_table = new $modelDbTableName;
        return $this->_table;
    }
 
    /**
     * Save a new entry
     * 
     * $data is an array in where u have the same key names
     * than in the table columns
     * If u want fill the "content" column in the table 
     * you should have a $data['content'].
     * Its working well with _getAppropriateForm() method
     * from the supportController class.
     * 
     * @param  array $data 
     * @param  string $table_name_with_cap
     * @return int|string
     */
    public function save(array $data, $table_name_with_cap)
    {
        //debug
        /*
        echo '$data avant : ';
        print_r($data);
        */
 
        $table  = $this->getTable($table_name_with_cap);
        $fields = $table->info(Zend_Db_Table_Abstract::COLS);
 
        //debug
        /*
        echo '$fields avant : ';
        print_r($fields);
        */
 
        // unset the element of $data which have no column in the table.
        foreach ($data as $field => $value) {
            if (!in_array($field, $fields)) {
                unset($data[$field]);
            }
        }
 
        //debug
        /*
        echo '$table_name_with_cap : ' . $table_name_with_cap;
        echo '$data apres : ';
        print_r($data);
        */
 
        //insert() method from Model_Support include the creation date 
        //then insert $data in the table
        return $table->insert($data);
    }
 
    /**
     * Update an entry
     * 
     * $data is an array in where u have the same key names
     * than in the table columns
     * If u want fill the "content" column in the table 
     * you should have a $data['content'].
     * 
     * @param  array $data 
     * @param  string $table_name_with_cap
     * @param  mixed $row 
     * @param  mixed $rowValue 
     * @return int|string
     */
    public function upToDate(array $data, $table_name_with_cap, $row, $rowValue)
    {
        //debug
        echo '$data avant : ';
        print_r($data);
 
        $table  = $this->getTable($table_name_with_cap);
        $fields = $table->info(Zend_Db_Table_Abstract::COLS);
 
        //debug
        echo '$fields avant : ';
        print_r($fields);
 
        // unset the element of $data which have no column in the table.
        foreach ($data as $field => $value) {
            if (!in_array($field, $fields)) {
                unset($data[$field]);
            }
        }
 
        // set the 'WHERE' for the update
        $where = '';
        if (is_array($row)){
           $where = $row . ' = ' . $rowValue;
           for($i=1; $i<count($row);$i++){
                $where .= ' AND ' . $row . ' = ' . $rowValue;    
           }
        }
        else {
            $where = $row . ' = ' . $rowValue;
        }
        $where = $table->getAdapter()->quote($where);
 
        //debug
        echo '$table_name_with_cap : ' . $table_name_with_cap;
        echo '$data apres : ';
        print_r($data);
        echo '$where : ';
        print_r($where);
 
        return $table->update($data, $where);
    }
 
	...
}
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
 
/**
 * Model_DbTable_Courses
 * 
 * @author
 * @version 0.01
 * 
 * application/default/models/DbTable/Courses.php
 */
 
// Particular methods for the table courses
// insert() : insert the immediate date in co_creation_date 
// 	and insert the datas in the courses table
// update() : update data for the targeted entry
 
 
class Model_DbTable_Courses extends Zend_Db_Table_Abstract{
 
	// table name
	protected $_name = "courses";
 
    /**
     * insert()
     * Insert new row
     *
     * Ensure that a timestamp is set for the created field.
     * 
     * @param  array $data 
     * @return int
     */
    public function insert(array $data)
    {
        $data['c_creation_date'] = date('Y-m-d H:i:s');
        $data['c_edit_date'] = $data['c_creation_date'];
        return parent::insert($data);
    }
 
    /**
     * update()
     * Do not allow updating of entries
     * 
     * @param  array $data 
     * @param  mixed $where 
     * @return void
     * @throws Exception
     * 
     * public function update(array $data, $where)
    */
    public function update(array $data, $where)
    {
        $data['c_edit_date'] = date('Y-m-d H:i:s');
        return parent::update($data, $where);
    }
 
}
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
// application/default/forms/Course.php
 
/**
 * This is the support form.  It is in its own directory in the application 
 * structure because it represents a "composite asset" in your application.  By 
 * "composite", it is meant that the form encompasses several aspects of the 
 * application: it handles part of the display logic (view), it also handles 
 * validation and filtering (controller and model).  
 */
class Form_Course extends Zend_Form
{
    /**
     * init()
	 * initialization routine
     *
     * @see    http://framework.zend.com/manual/en/zend.form.html
     * @return void
     */ 
    public function init()
    {
        // if it's an edit we get the last course datas
        $registry = Zend_Registry::getInstance(); 
        if ($registry->isRegistered('courses')){
            $courses = $registry->get('courses');
            $this->addElement('textarea', 'c_edit_comment', array(
                'label'      => 'Modifications apportées par l\'édition :',
                'required'   => false,
                'filters'    => array('StringTrim'),
                'order'		 => 2,
            ));
        }
        else{
            $courses['0']['c_title_raw'] = '';
            $courses['0']['c_description'] = '';
            $registry->set('courses', $courses);
        }
 
        // set the method for the display form to POST
        $this->setMethod('post');
 
        $this->addElement('text', 'c_title_raw', array(
            'label'      => 'Titre du cours :',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'value'      => $courses['0']['c_title_raw'],
        ));
 
        $this->addElement('textarea', 'c_description', array(
            'label'      => 'Description du cours :',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'value'      => $courses['0']['c_description'],
        ));
 
        $this->addElement('captcha', 'captcha', array(
            'label'      => 'Entrez les lettres suivantes svp :',
            'required'   => true,
            'captcha'    => array('captcha' => 'Figlet', 'wordLen' => 5, 'timeout' => 300)
        ));
 
        // add the submit button
        $this->addElement('submit', 'submit', array(
            'label'    => 'Enregistrer',
        ));
    }
}
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
31
32
33
34
<?php
/**
 * new-course.phtml
 * 
 * @author
 * @version 0.01
 * 
 * application/default/views/scripts/courses/new-course.phtml
 */
 
// Creation of a new course
 
$this->headTitle('Nouveau cours');
//$this->headScript('');
$this->headStyle('./styles/style.css');
?>
 
<p><a href="<?= $this->url(
    array(
        'controller' => 'courses',
    ), 
    'default', 
    true) ?>">Liste des cours</a></p>
<p><a href="<?= $this->url(
    array(
        'controller' => 'courses',
        'action'     => 'new-lesson'
    ), 
    'default', 
    true) ?>">Créer une leçon</a></p>
 
<p>Nouveau cours :</p>
 
<?= $this->form ?>
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
31
32
33
34
<?php
/**
 * edit-course.phtml
 * 
 * @author
 * @version 0.01
 * 
 * application/default/views/scripts/courses/edit-course.phtml
 */
 
// Edition of an existing course
 
$this->headTitle('Modification de cours');
//$this->headScript('');
$this->headStyle('./styles/style.css');
?>
 
<p><a href="<?= $this->url(
    array(
        'controller' => 'courses',
    ), 
    'default', 
    true) ?>">Liste des cours</a></p>
<p><a href="<?= $this->url(
    array(
        'controller' => 'courses',
        'action'     => 'new-lesson'
    ), 
    'default', 
    true) ?>">Créer une leçon</a></p>
 
<p>Editer le cours :</p>
 
<?= $this->form ?>
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
31
32
33
34
35
36
37
38
<?php
 
/**
 * index.phtml
 * 
 * @author
 * @version 0.01
 * 
 * application/default/views/scripts/courses/index.phtml
 */
 
// List the available courses
 
$this->headTitle('Home');
?>
<br />
<p>Cours disponibles: </p>
<br />
 
<!-- exemple pour le test, remplace le code original un peu long -->
 
<p>
	<a href="<?= $this->url(array(	'controller' 	=> 'courses',
        							'action'   		=> 'edit-course',
									'c_id' 	=> 3,), 
    						'default', 
    						true) ?>">
    	edit the 3rd course
	</a>
</p>
 
<p><a href="<?= $this->url(
    array(
        'controller' => 'courses',
        'action'     => 'new-course'
    ), 
    'default', 
    true) ?>">Créer un cours</a></p>
exemple d'un retour :
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 
	<head>
		...
	</head>
 
	<body>
 
		<a href="/ZendStudio/plateformeDeCours/public/login">login</a>	   		
   		<div id="nav"></div>
   		<div id="content">
<p><a href="/ZendStudio/plateformeDeCours/public/courses">Liste des cours</a></p>
<p><a href="/ZendStudio/plateformeDeCours/public/courses/new-lesson">Créer une leçon</a></p>
 
<p>Editer le cours :</p>
 
<form> <!--formulaire--> </form>Array
(
    [0] => Array
        (
            [c_id] => 3
            [c_title_raw] => Moyen-age
            [c_title_formatted] => 
            [c_description] => période du moyen-age
            [c_creator_id] => 
            [c_creation_date] => 2009-02-25 03:51:18
            [c_editor_id] => 
            [c_edit_date] => 2009-02-26 19:02:06
            [c_edit_comment] => 
        )
 
)
$data avant : Array
(
    [c_edit_comment] => 
    [c_title_raw] => Renaissance
    [c_description] => période du Renaissance
    [captcha] => Array
        (
            [id] => 898338cc80740ce7f360153733ece59e
            [input] => ZIQIK
        )
 
    [submit] => Enregistrer
)
$fields avant : Array
(
    [0] => c_id
    [1] => c_title_raw
    [2] => c_title_formatted
    [3] => c_description
    [4] => c_creator_id
    [5] => c_creation_date
    [6] => c_editor_id
    [7] => c_edit_date
    [8] => c_edit_comment
)
$table_name_with_cap : Courses$data apres : Array
(
    [c_edit_comment] => 
    [c_title_raw] => Renaissance
    [c_description] => période du Renaissance
)
$where : 'c_id = 3'$formValues : Array
(
    [c_edit_comment] => 
    [c_title_raw] => Renaissance
    [c_description] => période du Renaissance
    [captcha] => Array
        (
            [id] => 898338cc80740ce7f360153733ece59e
            [input] => ZIQIK
        )
 
    [submit] => Enregistrer
)
$form_name_with_cap : Courseformulaire valide</div>
 
			</body>
 
</html>
j'espere que vous pourrez m'aider !