Bonjour,

Voici mon index.phtml :

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

<?php $this->headScript()->captureStart(); ?>
var baseUrl = '<?php echo $this->baseUrl()?>';
<?php $this->headScript()->captureEnd(); ?>

<?php
      // mettre les scripts dans l'ordre

      // placer celui-ci à un offset particulier pour s'assurer
      // de le charger en dernier
      $this->headScript()
      ->appendFile('scripts/woutils.js')
      ->appendFile('scripts/calc-selector.js')
      ->prependFile('scripts/jquery143.js');
      
      echo $this->headScript();
?>


<input type="button" name="calculer" value="Tester" onClick="tester();">

<form name="calculateurimc" method="post" action="Index/imc">
	<table width="400px" height="91px">
		<tbody>

         <tr>
				<td width="400" valign="top" align="center" rowspan="1" colspan="3">
					<h1>Calculateur IMC</h1>
				</td>
			</tr>

         <tr>
				<td width="400" valign="top" align="center">
					Taille (en cm) : <input type="text" maxlength="5" size="5" name="taille" id="idTaille">
				</td>

            <td width="400" valign="top" align="center">
					Poids : <input type="text" maxlength="5" size="5" name="poids" id="idPoids">
				</td>
			</tr>
			
			<tr>
				<td width="400" valign="top" align="right" rowspan="1" colspan="3">
					<input type="submit" name="calculer" value="Calculer IMC">
				</td>
			</tr>
			
			<tr>
            <td width="400" valign="top" align="center" id="idImc">
					<!--Imc : <input type="text" maxlength="5" size="5" name="imc">-->
				</td>
			</tr>
			
		</tbody>
	</table>
</form>
Mon fichier calc-selector.js :

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
function tester()
{
   var _taille = $('input[name="taille"]')[0].value;
   var _poids = $('input[name="poids"]')[0].value;

   $.ajax(
      { // $.get n'est qu'une abbréviation de $.ajax avec des options de bases
            url: baseUrl+'/index/imc/format/html/',
          type: "GET",
          dataType: "html",
          data: {taille: _taille, poids: _poids},
          success: tester_rep
      }
   );
}

function tester_rep(reponse)
{
   //dom_ajouterNoeud(document, $('#idImc')[0], "h1", "test ajout dynamique")
   
   $('#idImc')[0].innerHTML = reponse;
}
Et enfin mon IndexController :

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
 
<?php
 
class IndexController extends Zend_Controller_Action
{
    private $calc;
 
    public function init()
    {
        /* Initialize action controller here */
 
      $ajaxContext = $this->_helper->getHelper('AjaxContext');
	   $ajaxContext->addActionContext('imc', 'json')
	               ->initContext();
 
    }
 
    public function indexAction()
    {
        // action body
 
    }
 
    public function imcAction()
    {
        // action body     
 
      $taille = $_GET['taille'];
      $poids = $_GET['poids'];
 
      $imc = $this->calc->imc($taille, $poids);            
 
      echo $imc;            
    }
 
    public function preDispatch()
    {
		parent::preDispatch();
 
      $this->calc = new Perso_CalculateurImc();
	 }
}
l'url que je transmet me permet bien "d'atteindre" mon action imcAction.

Mais un truc m'empêche quand même de dormir :

Mon baseurl vaut "/test2/public".
Donc l'url complete transmise dans $.ajax() est : "/test2/public/index/imc/format/html/".

Or mon IndexController se trouve dans "\test2\application\controllers".
Donc pour moi, l'url à transmettre à $.ajax() devrait plutôt être : "\test2\application\controllers\index\imc\format/html/"

Bref, je ne comprends pas trop comment zf retrouve l'action imcAction de mon controleur IndexController puisque le chemin que je lui indique est à priori faux. Si quelqu'un peut m'éclairer.

Je voudrais être sûr que ça ne fonctionne pas par hasard.