Zend FR

Consultez la FAQ sur le ZF avant de poster une question

Vous n'êtes pas identifié.

#1 29-01-2011 17:36:01

loby
Nouveau membre
Date d'inscription: 27-01-2011
Messages: 4

Message: SQLSTATE[42S02]: Base table or view not found: 1146

Bonjour,
je débute avec zend et j'ai un problème lorsque j'essaye de me connecter à une base de données pour récupérer les enregistrement d'une table

j'ai créer une application avec une base de données 'zenddatabase' et une table 'clients'
je me suis basé sur ce tutoriel pour sa création :
http://manual.zfdes.com/fr/learning.quickstart.html

sur ma page d'accueil j'ai juste un lien qui me propose de voir les clients inscrit dans la table 'clients'
quand je clic dessus voilà ce qui apparait :

Message: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'zenddatabase.application_model_dbtable_clients' doesn't exist
Stack trace:

#0 C:\wamp\www\testzend\library\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\wamp\www\testzend\library\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 C:\wamp\www\testzend\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE `Appli...', Array)
#3 C:\wamp\www\testzend\library\Zend\Db\Adapter\Pdo\Mysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `Appli...')
#4 C:\wamp\www\testzend\library\Zend\Db\Table\Abstract.php(834): Zend_Db_Adapter_Pdo_Mysql->describeTable('Application_Mod...', NULL)
#5 C:\wamp\www\testzend\library\Zend\Db\Table\Abstract.php(873): Zend_Db_Table_Abstract->_setupMetadata()
#6 C:\wamp\www\testzend\library\Zend\Db\Table\Abstract.php(980): Zend_Db_Table_Abstract->_setupPrimaryKey()
#7 C:\wamp\www\testzend\library\Zend\Db\Table\Select.php(100): Zend_Db_Table_Abstract->info()
#8 C:\wamp\www\testzend\library\Zend\Db\Table\Select.php(78): Zend_Db_Table_Select->setTable(Object(Application_Model_DbTable_Clients))
#9 C:\wamp\www\testzend\library\Zend\Db\Table\Abstract.php(1016): Zend_Db_Table_Select->__construct(Object(Application_Model_DbTable_Clients))
#10 C:\wamp\www\testzend\library\Zend\Db\Table\Abstract.php(1314): Zend_Db_Table_Abstract->select()
#11 C:\wamp\www\testzend\application\models\ClientsMapper.php(31): Zend_Db_Table_Abstract->fetchAll()
#12 C:\wamp\www\testzend\application\controllers\ClientsController.php(7): Application_Model_ClientsMapper->getAll()
#13 C:\wamp\www\testzend\library\Zend\Controller\Action.php(513): ClientsController->indexAction()
#14 C:\wamp\www\testzend\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
#15 C:\wamp\www\testzend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#16 C:\wamp\www\testzend\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#17 C:\wamp\www\testzend\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#18 C:\wamp\www\testzend\public\index.php(26): Zend_Application->run()
#19 {main}

Request Parameters:

array(3) {
  ["controller"]=>
  string(7) "clients"
  ["action"]=>
  string(5) "index"
  ["module"]=>
  string(7) "default"
}

et voici mon code :

fichier application/controllers/ClientsController.php

<?php
class ClientsController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $clients = new Application_Model_ClientsMapper();
        $this->view->entries = $clients->getAll();
    }
}
?>

fichier application/models/ClientsMapper.php

<?php
class Application_Model_ClientsMapper
{
    protected $_dbTab;
   
     public function setDbTab($dbTable)
    {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Invalid table data gateway provided');
        }
        $this->_dbTab = $dbTable;
        return $this;
    }
   
   
    public function getDbTab() 
    {
        if($this->_dbTab === null)
        {
            //$this->dbTab = new Application_Model_DbTable_Clients();
            $this->setDbTab('Application_Model_DbTable_Clients');
        }
        return $this->_dbTab;
    }
   
    public function getAll()   
    {
        $dataTab = $this->getDbTab()->fetchAll();
        $results = array();
        foreach($dataTab as $row)
        {
            $entry = new Application_Model_Clients();
            $entry->setId($row->id)
            ->setNom($row->nom)
            ->setPrenom($row->prenom)
            ->setEmail($row->email);
            $results[] = $entry;
        }
        return $results;
    }
}
?>

fichier application/models/Clients.php

<?php
class Application_Model_Clients
{
    protected $_id;   //représentation de tous les champs de la table dans des attributs.
    protected $_nom;
    protected $_prenom;
    protected $_email;
   
    public function __construct(array $options = null)   
    {
        if(is_array($options))
        {
            $methods = get_class_methods($this);
            foreach($options as $key => $value)
            {
                $method = 'set'.ucfirst($key);
                if(in_array($method,$methods))
                {
                    $this->$method($value);
                }
            }
            return $this;
        }
       
    }
   
    public function setId($id)
    {
        $this->_id = (int)$id;
    }
   
    public function setNom($nom)
    {
        $this->_nom = (string)$nom;
    }
   
    public function setPrenom($prenom)
    {
        $this->_prenom = (string)$prenom;
    }
    public function setEmail()
    {
        $this->_email = (string)$email;
    }

   
}
?>

fichier application/models/DbTable/Clients.php

<?php
class Application_Model_DbTable_Clients extends Zend_Db_Table_Abstract
{
    protected $name = 'clients';
    protected $id = 'id';
}
?>

et le fichier application/configs/application.ini

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
phpSettings.date.timezone = "Europe/Paris"
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = zenddatabase
resources.db.isDefaultTableAdapter = true


[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

je suis perdu :-(
quelqu'un pourrait m'aider?

Hors ligne

 

#2 29-01-2011 18:14:05

sekaijin
Membre
Date d'inscription: 17-08-2007
Messages: 1137

Re: Message: SQLSTATE[42S02]: Base table or view not found: 1146

ben il te dit que ta table n'existe pas dans ta base de données

Hors ligne

 

#3 29-01-2011 18:25:09

loby
Nouveau membre
Date d'inscription: 27-01-2011
Messages: 4

Re: Message: SQLSTATE[42S02]: Base table or view not found: 1146

salut pourtant j'ai bien une table 'clients' dans ma db.

Hors ligne

 

#4 29-01-2011 18:29:31

loby
Nouveau membre
Date d'inscription: 27-01-2011
Messages: 4

Re: Message: SQLSTATE[42S02]: Base table or view not found: 1146

en fait je ne comprend pas à quel moment je commet une erreur pour qu'il aille me chercher une table qui s'appellerait 'application_model_dbtable_clients'

je pense avoir bien suivi le tuto, pourtant ca ne fonctionne pas

Hors ligne

 

#5 29-01-2011 19:25:09

mikaelkael
Administrateur
Lieu: Donges
Date d'inscription: 18-06-2007
Messages: 1176
Site web

Re: Message: SQLSTATE[42S02]: Base table or view not found: 1146

Hello,

Le nom de la table doit être fourni avec la variable :

Code:

$_name <- avec l'underscore

@+


Less code = less bugs
Contributeur ZF - ZCE - ZFCE - Doc ZF (CHM & PDF) - Vice-trésorier AFUP 2011
Ubuntu 11.04 - ZendServer

Hors ligne

 

#6 30-01-2011 09:28:00

loby
Nouveau membre
Date d'inscription: 27-01-2011
Messages: 4

Re: Message: SQLSTATE[42S02]: Base table or view not found: 1146

génial merci! ca marche. Quand je pense que j'attrapai la migraine pour un underscore, comme quoi en programmation chaque détails compte hmm
merci

Hors ligne

 

Pied de page des forums

Propulsé par PunBB
© Copyright 2002–2005 Rickard Andersson
Traduction par punbb.fr

Graphisme réalisé par l'agence Rodolphe Eveilleau
Développement par Kitpages