Précédent   Forum des professionnels en informatique > PHP > Outils > Zend > Zend Framework
Zend Framework Forum d'entraide sur la programmation PHP avec Zend Framework. Avant de poster -> FAQ ZF, Cours ZF
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 27/01/2011, 00h09   #1
Invité de passage
 
Inscription : janvier 2011
Messages : 12
Détails du profil
Informations forums :
Inscription : janvier 2011
Messages : 12
Points : 2
Points : 2
Par défaut inclure les class héritée de Zend_Db_Table

Bonjour,

je tente de comprendre et de mettre en place un bootstrap pour une application zend

je pense avoir fait le minimum pour pouvoir démarrer, mais le problème c'est que je n'arrive pas créer mes class modèles, celles qui héritent de Zend_Db_Table

je vous montre le code pour être plus claire

fichier testzend/public/index.php
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
 
<?php
 
// Inclusion de la classe Zend_Loader
require_once 'Zend/Loader/Autoloader.php';
 
set_include_path('.'
    . PATH_SEPARATOR . 'C:\wamp\www\testzend\application\models'
    . PATH_SEPARATOR . get_include_path());
 
 
 
 
$loader = Zend_Loader_Autoloader::getInstance();
Zend_Controller_Front::run('../application/controllers');
 
 
$db = new Zend_Db_Adapter_Pdo_Mysql(array(
'host ' => '127.0.0.1',
'username' => 'root',
'password' => '',
'dbname' => 'zendfacile'
));
 
$config = new Zend_Config_Ini('../application/config.ini','dev');
$db = Zend_Db::factory($config->database);
 
Zend_Db_Table::setDefaultAdapter($db);

fichier testzend/application/controllers/IndexController.php

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
<?php
 
class IndexController extends Zend_Controller_Action
{
   public function indexAction()
   {
 
 
   }
 
   function afficheramisAction()
	{
		require_once 'Ami.php';
		$this->view->title = "Liste de mes amis";
		$amis = new Ami();
		$this->view->amis = $amis->fetchAll();	
	}
 
}

fichier testzend/application/models/Ami.php
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
<?php
 
class Ami extends Zend_Db_Table
{
    protected $_name = 'ami';
	protected $_primary	= 'id';
	protected $_db;
	private static $last_insert_id;
	private static $name_file;
 
	public function insertRow($formulaire)
	{
 
		$data = array
		(
			'nom'=> $formulaire->getValue('nom'),
			'prenom'=>$formulaire->getValue('prenom'),
			'email'=>$formulaire->getValue('email'),
			'idType'=>$formulaire->getValue('idType')
 
		);
 
		self::$name_file = $formulaire->getValue('file');
 
		//$this->insert($data), en plus d'ajouter des données, renvoie le dernier id incrémenté
		self::$last_insert_id = $this->insert($data);
 
 
 
	}
 
	public function updateRow($formulaire)
	{
		$id = (int)$formulaire->getValue('id');
 
		$data = array
		(
			'nom'=>$formulaire->getValue('nom'),
			'prenom'=>$formulaire->getValue('prenom'),
			'email'=>$formulaire->getValue('email'),
			'idType'=>$formulaire->getValue('idType')
		);
 
		$where=$this->getAdapter()->quoteInto('id = ?', $id);
 
		$this->update($data,$where);
 
	}
 
	public function deleteRow($id)
	{
		$where = 'id = '.$id;
        $this->delete($where);
	}
 
	public function getLastInsertId(){
 
 
         return self::$last_insert_id;
 
 
    }
 
	public function getNameFile()
	{
		return self::$name_file;
 
	}
}
?>
la vue
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
<table border="1">
<tr>
	<th>Nom</th>
	<th>Prenom</th>
	<th>&nbsp;</th>
	<th>&nbsp;</th>
</tr>
 
<?php foreach($this->amis as $ami) : ?>
<tr>
	<td><?php echo $ami->nom;?></td>
	<td><?php echo $ami->prenom;?></td>
 
</tr>
<?php endforeach; ?>
</table>

quand je tape l'url http://testzend/index/afficheramis
je tombe sur la page d'erreur error.phtml

j'ai même rajouter au fichier php.ini dans la section include_path,
le chemin ;C:\wamp\www\testzend\application\models

quelqu'un pourrait m'éclairer? merci
leon86 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 04h46.


 
 
 
 
Partenaires

Hébergement Web