IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Instanciation d'une classe qui se passe mal


Sujet :

Langage PHP

  1. #1
    Membre averti Avatar de chatofor
    Profil pro
    Inscrit en
    Août 2009
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 59
    Par défaut Instanciation d'une classe qui se passe mal
    Bonjour,

    Je code selon "mon" framework, que je développe d'après un cours. J'ai un formulaire de commentaire relié à un système de news.

    Lorsque j'instancie la classe Commentaires (ce qui se fait lorsqu'on valide le formulaire), j'ai cette erreur qui se produit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Warning: require(/var/www/html/Framework/Web/../Library/Entities/Commentaires.php): failed to open stream: No such file or directory in /var/www/html/Framework/Library/autoload.php on line 152
    J'ai un autoload dont je ne comprends pas du tout le fonctionnement, je n'ai pas lu le code et j'espère que quelqu'un ici aura une idée de piste à creuser...


    Autre chose, si j'instancie la classe Commentaires avec un antislash devant, j'ai cette erreur qui se produit à la place de l'autre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Fatal error: Uncaught Error: Class 'Commentaires' not found in /var/www/html/Framework/Apps/Frontend/Modules/Articles/ArticlesController.php:72 Stack trace: #0 /var/www/html/Framework/Library/BackController.php(35): Apps\Frontend\Modules\Articles\ArticlesController->executeCommenter(Object(Library\HTTPRequest)) #1 /var/www/html/Framework/Apps/Frontend/FrontendApplication.php(19): Library\BackController->execute() #2 /var/www/html/Framework/Web/Bootstrap.php(35): Apps\Frontend\FrontendApplication->run() #3 {main} thrown in /var/www/html/Framework/Apps/Frontend/Modules/Articles/ArticlesController.php on line 72
    Je pense que c'est une erreur de namespace ou quelque chose comme ça mais j'ai vraiment du mal, j'ai essayé un peu au pif pas mal de modifications mais ça coince toujours...

  2. #2
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 693
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 693
    Par défaut
    C'est un problème de chemin et c'est donc , comme tu t'en doute déjà, un problème avec ton autoloader.
    Il va falloir que tu comprenne comment il marche , pour pouvoir résoudre ton problème.

    Le namespace joue également un role puisqu'il rentre dans le fonctionnement de l'autoloader.
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #3
    Membre averti Avatar de chatofor
    Profil pro
    Inscrit en
    Août 2009
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 59
    Par défaut
    Tu seras peut-être d'accord avec moi pour dire que c'est assez indigeste :

    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
    <?php
     
    /*
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     * This software consists of voluntary contributions made by many individuals
     * and is licensed under the MIT license. For more information, see
     * <http://www.doctrine-project.org>.
     */
     
    /**
     * SplClassLoader implementation that implements the technical interoperability
     * standards for PHP 5.3 namespaces and class names.
     *
     * http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1
     *
     *     // Example which loads classes for the Doctrine Common package in the
     *     // Doctrine\Common namespace.
     *     $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
     *     $classLoader->register();
     *
     * @license http://www.opensource.org/licenses/mit-license.html  MIT License
     * @author Jonathan H. Wage <jonwage@gmail.com>
     * @author Roman S. Borschel <roman@code-factory.org>
     * @author Matthew Weier O'Phinney <matthew@zend.com>
     * @author Kris Wallsmith <kris.wallsmith@gmail.com>
     * @author Fabien Potencier <fabien.potencier@symfony-project.org>
     */
    class SplClassLoader
    {
        private $_fileExtension = '.php';
        private $_namespace;
        private $_includePath;
        private $_namespaceSeparator = '\\';
     
        /**
         * Creates a new <tt>SplClassLoader</tt> that loads classes of the
         * specified namespace.
         * 
         * @param string $ns The namespace to use.
         */
        public function __construct($ns = null, $includePath = null)
        {
            $this->_namespace = $ns;
            $this->_includePath = $includePath;
        }
     
        /**
         * Sets the namespace separator used by classes in the namespace of this class loader.
         * 
         * @param string $sep The separator to use.
         */
        public function setNamespaceSeparator($sep)
        {
            $this->_namespaceSeparator = $sep;
        }
     
        /**
         * Gets the namespace seperator used by classes in the namespace of this class loader.
         *
         * @return void
         */
        public function getNamespaceSeparator()
        {
            return $this->_namespaceSeparator;
        }
     
        /**
         * Sets the base include path for all class files in the namespace of this class loader.
         * 
         * @param string $includePath
         */
        public function setIncludePath($includePath)
        {
            $this->_includePath = $includePath;
        }
     
        /**
         * Gets the base include path for all class files in the namespace of this class loader.
         *
         * @return string $includePath
         */
        public function getIncludePath()
        {
            return $this->_includePath;
        }
     
        /**
         * Sets the file extension of class files in the namespace of this class loader.
         * 
         * @param string $fileExtension
         */
        public function setFileExtension($fileExtension)
        {
            $this->_fileExtension = $fileExtension;
        }
     
        /**
         * Gets the file extension of class files in the namespace of this class loader.
         *
         * @return string $fileExtension
         */
        public function getFileExtension()
        {
            return $this->_fileExtension;
        }
     
        /**
         * Installs this class loader on the SPL autoload stack.
         */
        public function register()
        {
            spl_autoload_register(array($this, 'loadClass'));
        }
     
        /**
         * Uninstalls this class loader from the SPL autoloader stack.
         */
        public function unregister()
        {
            spl_autoload_unregister(array($this, 'loadClass'));
        }
     
        /**
         * Loads the given class or interface.
         *
         * @param string $className The name of the class to load.
         * @return void
         */
        public function loadClass($className)
        {
            if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
                $fileName = '';
                $namespace = '';
                if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
                    $namespace = substr($className, 0, $lastNsPos);
                    $className = substr($className, $lastNsPos + 1);
                    $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
                }
                $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
     
                require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
            }
        }
    }

  4. #4
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 506
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 506
    Par défaut
    Ton fichier se trouve bien là ? : /var/www/html/Framework/Library/Entities/Commentaires.php

  5. #5
    Membre averti Avatar de chatofor
    Profil pro
    Inscrit en
    Août 2009
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 59
    Par défaut
    Nom : problemePOO2.png
Affichages : 150
Taille : 53,3 Ko

    Oui comme tu peux le voir sur cette capture d'écran.

  6. #6
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 506
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 506
    Par défaut
    OK, tu peux me retourner le résultat de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ls -la /var/www/html/Framework/Library/Entities/Commentaires.php

Discussions similaires

  1. [JADE] instancier un objet avec paramètres d'une classe qui hérite d'Agent
    Par Hind4Dev dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 20/04/2017, 21h14
  2. Une addition qui se passe mal
    Par Romanodi13 dans le forum ActionScript 3
    Réponses: 6
    Dernier message: 30/12/2008, 14h20
  3. Réponses: 2
    Dernier message: 21/04/2006, 21h18
  4. Réponses: 14
    Dernier message: 14/03/2005, 10h16
  5. destruction d'une classe qui herite de CDialog
    Par philippe V dans le forum MFC
    Réponses: 2
    Dernier message: 03/02/2004, 18h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo