2013-10-26 2 views
-1
Warning: spl_object_hash() expects parameter 1 to be object, string given in 
/var/www/sitetwo/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1367 

내가 Category.phpProduct.php는 PHP 응용 프로그램/콘솔 명령을 통해 YML 매핑 주석을 사용하여 MainBlogBundle를 만들었습니다. 추가/수정/삭제/쇼 행동에 대한 CRUD 작업을 사용한 후 나는 카테고리를 추가하려고하고 Add category form를 제출 한 후 나는 GitHub의에서 내 샘플 코드를 게시하고 아래의 데이터베이스 스크립트입니다경고 : spl_object_hash는() 매개 변수 1 개체를 할 것으로 기대

Warning: spl_object_hash() expects parameter 1 to be object, string given in 
/var/www/sitetwo/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1367 

를 얻을. 위의 코멘트에 명시된 바와 같이

[email protected]:veerpartap/ProblemSymfony.git

/****************************************************************************/ 

-- phpMyAdmin SQL Dump 
-- version 3.4.10.1deb1 
-- http://www.phpmyadmin.net 
-- 
-- Host: localhost 
-- Generation Time: Oct 26, 2013 at 01:56 PM 
-- Server version: 5.5.32 
-- PHP Version: 5.5.3-1+debphp.org~precise+2 

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; 
SET time_zone = "+00:00"; 

-- 
-- Database: `sitetwo` 
-- 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `category` 
-- 

CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `Company` 
-- 

CREATE TABLE IF NOT EXISTS `Company` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`company_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL, 
`owner_name` varchar(150) COLLATE utf8_unicode_ci NOT NULL, 
`status` tinyint(1) NOT NULL, 
`created` datetime NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ; 

-- 
-- Dumping data for table `Company` 
-- 

INSERT INTO `Company` (`id`, `company_name`, `address`, `owner_name`, `status`, `created`) VALUES 
(1, 'My First Company', 'Street 5A Sector 85 Chandigarh 1665588', 'Mr. Prateek Kumar', 1, '2013-09-06 00:00:00'), 
(2, 'My Second Private Company', 'Street 34N Sector 89, Chandigarh 165898', 'Mr. Saurabh Shuja', 1, '2013-09-07 00:00:00'); 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `Post` 
-- 

CREATE TABLE IF NOT EXISTS `Post` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`title` varchar(250) COLLATE utf8_unicode_ci NOT NULL, 
`body` longtext COLLATE utf8_unicode_ci NOT NULL, 
`published` datetime NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `posts` 
-- 

CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`title` varchar(250) COLLATE utf8_unicode_ci NOT NULL, 
`body` longtext COLLATE utf8_unicode_ci NOT NULL, 
`published` datetime NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `products` 
-- 

CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`category_id` int(11) DEFAULT NULL, 
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, 
`price` decimal(10,0) NOT NULL, 
`description` longtext COLLATE utf8_unicode_ci NOT NULL, 
PRIMARY KEY (`id`), 
KEY `IDX_B3BA5A5A12469DE2` (`category_id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; 

-- -------------------------------------------------------- 

-- 
-- Table structure for table `User` 
-- 

    CREATE TABLE IF NOT EXISTS `User` (
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `first_name` varchar(150) NOT NULL, 
    `last_name` varchar(150) NOT NULL, 
    `sex` tinyint(1) DEFAULT NULL, 
    `date_of_birth` datetime DEFAULT NULL, 
    `education` varchar(10) NOT NULL, 
    `mobile` varchar(10) NOT NULL, 
    `email` varchar(100) NOT NULL, 
    `address` varchar(200) NOT NULL, 
    `status` tinyint(1) DEFAULT NULL, 
    PRIMARY KEY (`id`) 
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; 

    -- 
    -- Dumping data for table `User` 
    -- 

    INSERT INTO `User` (`id`, `first_name`, `last_name`, `sex`, `date_of_birth`, `education`, `mobile`, `email`, `address`, `status`) VALUES 
    (1, 'Veerpartap', 'Singh', 1, '2008-11-24 00:00:00', 'MCA', '71505897', '[email protected]', 'hl 99 phase 2 sas nagar mohali', 1), 
    (2, 'Vicky', 'Sharma', 1, '2008-05-09 00:00:00', 'MCA', '88754257', '[email protected]', 'Village Burari, Jila Nawanshar', 1); 

    -- 
    -- Constraints for dumped tables 
    -- 

    -- 
    -- Constraints for table `products` 
    -- 
    ALTER TABLE `products` 
    ADD CONSTRAINT `FK_B3BA5A5A12469DE2` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`); 

/****************************************************************************/ 
+0

예외가 발생하면 정확히 무엇을 하려는지 설명해 주시겠습니까? 캐시를 비우셨습니까? – nifr

+0

btw 님이 귀하의 프로필 정보에 제공된 [개인 홈페이지] (http://veerpartap.com/)를보고 약간 "실수"를 발견했습니다. 올바른 용어는 소프트웨어 ** 기술자 **가 아닌 * enginner * 또는 내가 이해하지 못하는 일종의 단어 놀이입니까? :) – nifr

+0

정보를 제공해 주셔서 감사 드리며 그 오타를 수정하십시오. 이 문제에 관해서는 ArrayCollection 클래스를 범주 컨트롤러에 포함시켜야한다는 것을 알게되었습니다. 그 라인을 추가하면 제품 섹션에있는 다른 오류가 나타납니다. 선택 필드로 전달 된 "Main \ BlogBundle \ Entity \ Category"유형의 객체에서 "__toString()"메소드를 찾을 수 없습니다. 대신 사용자 정의 getter를 읽으려면 "property"옵션을 원하는 속성 경로로 설정하십시오. " –

답변

0

는 문제는 내가 컨트롤러 파일의 Arrarycollection 네임 스페이스를 포함하지 오전에 대해이었다. 그러나 네임 스페이스를 포함시킨 후에는 새로운 제품을 추가하는 동안 또 다른 오류가 발생합니다.

다음은 오류 메시지입니다. "__toString()"메서드는 선택 필드의 Main \ BlogBundle \ Enity \ Category 유형의 개체에서 foudn되지 않았습니다.

이 오류의 경우 Category 엔티티에 __toString() 메소드를 추가해야합니다. 예를 들어

public function __toString() { return $this->name; } 

PHP의 매직 방법 __toString() 오브젝트의 텍스트 표현을 제시하는 데 사용된다. 이 경우 카테고리 이름은 관련 엔티티의 양식에서 카테고리를 선택할 때 사용됩니다.

0

클래스에서 __toString() 오류가 발생하면 XxxxxType이 AbstractType을 확장합니다. 빌더에서 필드 정의를 추가 할 수 있습니다. 엔티티를 수정할 필요가 없습니다.

$builder 
      ->add('enquete','entity',array('class' => 'AdequatSipBundle:Enquete', 
       'property' => 'Id', 'read_only'=>true)) 
      ->add('produit','entity',array('class' => 'AdequatSipBundle:Produit', 
       'property' => 'Name', 'read_only'=>true)) 
관련 문제