2012-08-02 15 views
17

ठीक से पुन: प्राप्त नहीं कर सकता है ठीक है, मैं अब दो घंटों तक रहा हूं और मुझे लगता है कि कुछ अन्य लोगों को यह त्रुटि हुई है, लेकिन मैं अपने कारणों/संकल्पों से मेल नहीं खा सकता।symfony2 घातक त्रुटि कक्षा

गंभीर त्रुटि: की आवश्यकता होती है() [function.require]: लाइन 55 पर /var/www/biztv_symfony/vendor/symfony/src/Symfony/Component/ClassLoader/DebugUniversalClassLoader.php में वर्ग companycontroller redeclare नहीं कर सकते

टर्मिनल एक बेहतर त्रुटि संदेश देता है जो मुझे वास्तविक वर्ग के अंतिम खंड पर इंगित करता है जिसमें यह समस्या (पुन: प्रयास करने की कोशिश कर रहा है) की रिपोर्ट करता है।

अगर मैं फ़ाइल कंपनी को नियंत्रित या नाम बदलता हूं तो नियंत्रक.एफ़.पी. यह एक सिम्फनी 2 त्रुटि फेंकता है और कहता है कि यह कक्षा की तलाश में गया लेकिन उसे यह नहीं मिला कि इसकी अपेक्षा की गई थी।

यदि मैं फ़ाइल को अपनी जगह पर वापस रखता हूं, तो अपाचे एक php त्रुटि फेंकता है जिसमें कहा गया है कि क्लास कंपनी नियंत्रक को फिर से नहीं बदला जा सकता है।

मेरे पास केवल एक बार है ?!

यहाँ पूरी क्लास है ... अगर कोई कोशिश करते हैं और मुझे बाहर मदद करने के लिए धैर्य है ...

<?php 

use Symfony\Bundle\FrameworkBundle\Controller\Controller; 

use BizTV\BackendBundle\Entity\company; 
use BizTV\BackendBundle\Form\companyType; 

/** 
* company controller 
* 
*/ 

class companyController extends Controller 
{ 
    /** 
    * Lists all company entities. 
    * 
    */ 
    public function indexAction() 
    { 
     $em = $this->getDoctrine()->getEntityManager(); 

     $entities = $em->getRepository('BizTVBackendBundle:company')->findAll(); 

     return $this->render('BizTVBackendBundle:company:index.html.twig', array(
      'entities' => $entities 
     )); 
    } 

    /** 
    * Finds and displays a company entity. 
    * 
    */ 
    public function showAction($id) 
    { 
     $em = $this->getDoctrine()->getEntityManager(); 

     $entity = $em->getRepository('BizTVBackendBundle:company')->find($id); 

     if (!$entity) { 
      throw $this->createNotFoundException('Unable to find company entity.'); 
     } 

     $deleteForm = $this->createDeleteForm($id); 

     return $this->render('BizTVBackendBundle:company:show.html.twig', array(
      'entity'  => $entity, 
      'delete_form' => $deleteForm->createView(), 

     )); 
    } 

    /** 
    * Displays a form to create a new company entity. 
    * 
    */ 
    public function newAction() 
    { 
     $entity = new company(); 
     $form = $this->createForm(new companyType(), $entity); 

     return $this->render('BizTVBackendBundle:company:new.html.twig', array(
      'entity' => $entity, 
      'form' => $form->createView() 
     )); 
    } 

    /** 
    * Creates a new company entity. 
    * 
    */ 
    public function createAction() 
    { 
     $entity = new company(); 
     $request = $this->getRequest(); 
     $form = $this->createForm(new companyType(), $entity); 
     $form->bindRequest($request); 

     if ($form->isValid()) { 
      $em = $this->getDoctrine()->getEntityManager(); 
      $em->persist($entity); 
      $em->flush(); 

      /* Create adminuser for this company to go along with it */ 
      $userManager = $this->container->get('fos_user.user_manager'); 
      $user = $userManager->createUser(); 

      //make password (same as username) 
      $encoder = $this->container->get('security.encoder_factory')->getEncoder($user); //get encoder for hashing pwd later 
      $tempPassword = $entity->getCompanyName(); //set password to equal company name 

      //Get company 
      $tempCompanyId = $entity->getId(); //get the id of the just-inserted company (so that we can retrieve that company object below for relating it to the user object later) 
      $tempCompany = $em->getRepository('BizTVBackendBundle:company')->find($tempCompanyId); //get the company object that this admin-user will belong to 

      $user->setUsername($entity->getCompanyName() . "/admin"); //set username to $company/admin 
      $user->setEmail('admin.'.$entity->getCompanyName().'@example.com'); //set email to non-functioning (@example) 
      $user->setPassword($encoder->encodePassword($tempPassword, $user->getSalt())); //set password with hash 
      $user->setCompany($tempCompany); //set company for this user    
      $user->setConfirmationToken(null); //we don't need email confirmation of account 
      $user->setEnabled(true); //without a confirmation token, we of course also need to flag the account as enabled manually 
      $user->addRole('ROLE_ADMIN'); 

      $userManager->updateUser($user); 

      return $this->redirect($this->generateUrl('company_show', array('id' => $entity->getId()))); 

     } 

     return $this->render('BizTVBackendBundle:company:new.html.twig', array(
      'entity' => $entity, 
      'form' => $form->createView() 
     )); 
    } 

    /** 
    * Displays a form to edit an existing company entity. 
    * 
    */ 
    public function editAction($id) 
    { 
     $em = $this->getDoctrine()->getEntityManager(); 

     $entity = $em->getRepository('BizTVBackendBundle:company')->find($id); 

     if (!$entity) { 
      throw $this->createNotFoundException('Unable to find company entity.'); 
     } 

     $editForm = $this->createForm(new companyType(), $entity); 
     $deleteForm = $this->createDeleteForm($id); 

     return $this->render('BizTVBackendBundle:company:edit.html.twig', array(
      'entity'  => $entity, 
      'edit_form' => $editForm->createView(), 
      'delete_form' => $deleteForm->createView(), 
     )); 
    } 

    /** 
    * Edits an existing company entity. 
    * 
    */ 
    public function updateAction($id) 
    { 
     $em = $this->getDoctrine()->getEntityManager(); 

     $entity = $em->getRepository('BizTVBackendBundle:company')->find($id); 

     if (!$entity) { 
      throw $this->createNotFoundException('Unable to find company entity.'); 
     } 

     $editForm = $this->createForm(new companyType(), $entity); 
     $deleteForm = $this->createDeleteForm($id); 

     $request = $this->getRequest(); 

     $editForm->bindRequest($request); 

     if ($editForm->isValid()) { 
      $em->persist($entity); 
      $em->flush(); 

      return $this->redirect($this->generateUrl('company_edit', array('id' => $id))); 
     } 

     return $this->render('BizTVBackendBundle:company:edit.html.twig', array(
      'entity'  => $entity, 
      'edit_form' => $editForm->createView(), 
      'delete_form' => $deleteForm->createView(), 
     )); 
    } 

    /** 
    * Deletes a company entity. 
    * 
    */ 
    public function deleteAction($id) 
    { 
     $form = $this->createDeleteForm($id); 
     $request = $this->getRequest(); 

     $form->bindRequest($request); 

     if ($form->isValid()) { 
      $em = $this->getDoctrine()->getEntityManager(); 
      $entity = $em->getRepository('BizTVBackendBundle:company')->find($id); 

      if (!$entity) { 
       throw $this->createNotFoundException('Unable to find company entity.'); 
      } 

      $em->remove($entity); 
      $em->flush(); 
     } 

     return $this->redirect($this->generateUrl('company')); 
    } 

    private function createDeleteForm($id) 
    { 
     return $this->createFormBuilder(array('id' => $id)) 
      ->add('id', 'hidden') 
      ->getForm() 
     ; 
    } 
} 
+1

आप 'companyController' के लिए grep करने की कोशिश की काम किया? –

+2

आपके पास अपने नियंत्रक में नामस्थान परिभाषित नहीं है। शायद वह हो सकता है? – unairoldan

+0

धन्यवाद। मैंने बस इकाई के लिए क्रूड को पुन: उत्पन्न किया और यही वह है जो मैंने पाया - देर रात कल मैंने दस्तावेज़ के शीर्ष पर एक टिप्पणी जोड़ा - जिसने मैंने अपनी टिप्पणी लिखना शुरू किया था, उसी तरह नामस्थान लाइन को गलती से हाइलाइट किया होगा, इस प्रकार नामस्थान को बदलना एक टिप्पणी के साथ ... क्या थ्रेड के जवाब के रूप में आपकी टिप्पणी को चिह्नित करना संभव नहीं है? –

उत्तर

52

तो, पता चला है कि वहाँ moi द्वारा एक clumpsy टाइपो था।

लेकिन किसी और को जो Symfony2 में यह त्रुटि संदेश में चलाता है के लिए:

गंभीर त्रुटि: की आवश्यकता होती है() [function.require]: वर्ग redeclare नहीं कर सकते ...

यहाँ एक संकेत है: जाँच लें कि आपने गलती से हटा दिया है या टाइपो: उस फ़ाइल में नेमस्पेस को संपादित करें जिसमें कक्षा की परिभाषा शामिल है जो php दावों को फिर से परिभाषित करने का प्रयास कर रहा है।

php त्रुटि संदेश नहीं वास्तव में आपको लगता है कि देखने के लिए एक सुराग

+0

हाँ, ऐसा होता है ...: डी –

+0

इस उत्तर को स्वीकृत के रूप में चिह्नित करें, इसलिए इस प्रश्न को 'अनुत्तरित' –

+1

द्वारा फ़िल्टर नहीं किया जाएगा मेरे थके हुए मस्तिष्क से मुझे बचाने के लिए धन्यवाद। – mattalxndr

0

redeclare वर्ग देता है ... =) - संभावना वहाँ, एक ही नाम के साथ टो वर्गों है

0

कभी कभी अगर तुम मिल गया कॉपी/पेस्ट द्वारा बहकाया गया, अपने क्लासनाम, नामस्थान और अन्य "टाइपो" के लिए जांचें जो हो सकता था। (प्रतिलिपि/पेस्ट प्रोग्रामिंग का शैतान है: /)

0

अन्य उत्तरों के समान, मेरे मामले में मैंने कक्षा का नाम बदल दिया लेकिन फाइल नहीं थी। प्रत्येक वर्ग को उसी नाम से फ़ाइल में घोषित किया जाना चाहिए। तो उसे भी देखें।

0

मेरे मामले में, यह नामस्थान के तहत use कथन था जो समान वर्गनाम (लेकिन एक और पथ) का उपयोग करता था।

namespace Bsz\RecordTab; 
use \Bsz\Config\Libraries; // I used this in constructor 
class Libraries 
{ 
... 
} 

उपयोग के निर्देश के बिना, यह

संबंधित मुद्दे