警告:spl_object_hash()期望参数1为对象 [英] Warning: spl_object_hash() expects parameter 1 to be object
问题描述
/ var / www / sitetwo / vendor / doctrine / orm / lib / Doctrine / ORM / UnitOfWork.php line 1367
我使用 Category.php $创建了MainBlogBundle c $ c>和
Product.php
通过php app / console命令使用yml映射注释。在使用CRUD操作添加/编辑/删除/显示操作后,我尝试添加一个类别并提交添加类别表单
我得到
警告:spl_object_hash()期望参数1为对象,字符串在
/ var / www / sitetwo / vendor / doctrine / orm / lib / Doctrine中给出/ORM/UnitOfWork.php行1367
我在github上发布了我的示例代码,下面是数据库。
git@github.com:veerpartap / ProblemSymfony.git
/ ********************************** ****************************************** /
- phpMyAdmin SQL转储
- 版本3.4.10.1deb1
- http://www.phpmyadmin.net
-
- 主机:localhost
- 生成时间:2013年10月26日01:56 PM
- 服务器版本:5.5.32
- PHP版本:5.5.3-1 + debphp.org〜精准+ 2
SET SQL_MODE =NO_AUTO_VALUE_ON_ZERO;
SET time_zone =+00:00;
-
- 数据库:`sitetwo`
-
- ------------- -------------------------------------------
-
- 表`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;
- ---------------------------------------- ----------------
-
- 表'Company`的表结构
-
CREATE TABLE如果不存在`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;
-
- 转储表'Company`的数据
-
INSERT INTO`Company`(`id`,`company_name` ,地址,所有者,状态,已创建)VALUES
(1,我的第一个公司,5A行业85昌迪加1665588,Prateek Kumar先生,1, 2013-09-06 00:00:00'),
(2,我的第二私人公司,第34N行第89号,昌迪加尔165898,Saurabh Shuja先生,1 2013年-07 00:00:00');
- ---------------------------------------- ----------------
-
- 表'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;
- ---------------------------------------- ----------------
-
- 表'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;
- ---------------------------------------- ----------------
-
- 表`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;
- ---------------------------------------- ----------------
-
- 表'User`
-
$的表结构b $ b 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;
-
- 转储表'User'
-
INSERT INTO`User`(`id`,`first_name`) ,`last_name`,`sex`,`date_of_birth`,`education`,`mobile`,`email`,`address`,'status`)VALUES
(1,'Veerpartap','Singh' ,'2008-11-24 00:00:00','MCA','71505897','metveerpartapsingh@gmail.com','hl 99 phase 2 sas nagar mohali',1),
(2, 'Vicky','Sharma',1,'2008-05-09 00:00:00','MCA','88754257','vicky.sharma@gmail.com','Burla,Jila Nawanshar',1 );
-
- 转储表的限制
-
-
- 表`products`的限制
-
ALTER TABLE`products`
ADD CONSTRAINT`FK_B3BA5A5A12469DE2` FOREIGN KEY(`category_id`)参考`category`(`id`);
/ ******************************************* *********************************** /
如果您在类XxxxxType中获得__toString()错误,则可以将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))
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
I created MainBlogBundle with Category.php
and Product.php
using yml mapping annotation via php app/console commands. After using CRUD actions for add/edit/delete/show actions I tried to add a category and after submitting Add category form
I get the
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
I posted my sample code on github and below is the script of database.
git@github.com: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', 'metveerpartapsingh@gmail.com', 'hl 99 phase 2 sas nagar mohali', 1),
(2, 'Vicky', 'Sharma', 1, '2008-05-09 00:00:00', 'MCA', '88754257', 'vicky.sharma@gmail.com', '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`);
/****************************************************************************/
if you getthe __toString() error in a class XxxxxType extends AbstractType you can add the fiel definition in the builder, like this. No need to modify your entity.
$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))
这篇关于警告:spl_object_hash()期望参数1为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!