zf2 doctrine2如何在实体列中使用tinyint数据类型 - php

我在ZF2上使用Doctrine 2 ORM。

/**
 * 
 * @ORM\Column(type="tinyint", options={"default" = 1})
 */
protected $isActive;

正如我在support data type of doctrine中所见,如何创建tinyint类型的列,它不存在。

Commandline># ./vendor/bin/doctrine-module orm:validate-schema

[Mapping]  FAIL - The entity-class 'Application\Entity\User' mapping is invalid:
* The field 'Application\Entity\User#isActive' uses a non-existant type 'tinyint'.

  [Doctrine\DBAL\DBALException]
  Unknown column type "tinyint" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypeMap(). If this
  error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseT
  ypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.


orm:validate-schema

参考方案

使用columnDefinition,尽管它不是理想的解决方案,但可以达到目的。

/**
 * 
 * @ORM\Column(columnDefinition="TINYINT DEFAULT 1 NOT NULL")
 */
protected $isActive;

columnDefinition:DDL SQL代码段,在列名之后开始,并指定完整的(不可移植!)列定义。此属性允许使用高级RMDBS功能。但是,您应谨慎使用此功能及其后果。如果使用“ columnDefinition”,SchemaTool将不再正确检测列上的更改。

另外,您应该记住,“ type”属性仍然可以处理PHP和数据库值之间的转换。如果在用于表之间的联接的列上使用此属性,则还应该查看@JoinColumn。

PHP getallheaders替代 - php

我正在尝试从服务器上的apache切换到nginx。唯一的问题是我在PHP脚本中使用的getallheaders()函数,该函数不适用于Nginx。我已经尝试过用户在getallheaders函数上的php站点上提供的注释,但这并不返回所有请求标头。请告诉我如何解决这个问题。我真的想切换到Nginx。 参考方案 您仍然可以使用它,但是您必须像这里一样重新定义…

php Singleton类实例将在多个会话中保留吗? - php

举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…

PHP:将字符串拆分为字母和数字部分的最佳方法 - php

我有几个格式的字符串AA11 AAAAAA1111111 AA1111111 分离字符串的字母和数字部分的最佳方法(最有效)? 参考方案 如果它们都是一系列字母,然后是一系列数字,并且没有非字母数字字符,那么sscanf()可能比regexp更有效$example = 'AAA11111'; list($alpha,$numeric) =…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…