草庐IT

date_default_timezone_set

全部标签

php - Zend 框架 2 : Set options as "selected" in select list

我正在尝试将第二个产品设置为在列表中选中,但下面的代码不起作用。任何的想法。谢谢$this->add(array('type'=>'Zend\Form\Element\Select','name'=>'manufacturer','options'=>array('label'=>'Manufacturername','value_options'=>$this->getManufacturer(),'empty_option'=>'---selectmanufacturer---',),'attributes'=>array('value'=>2,'selected'=>true,)

php - 拉维尔 5 : How to retrieve records according to date?

我有一个名为entries的表,它的created_at被定义为DATE类型。例如,如何获取3月15日的记录?我尝试过的$post=Entry::where(\DB::raw('DATE(created_at)'),'=',date('2015-03-15'))->get()->toJSON();但它返回空结果。迁移Schema::create('entries',function(Blueprint$table){$table->increments('id');$table->integer('intern_id');$table->integer('company_id');$t

php - PHP date_create() 上的 Twig 异常

我想根据她的生日计算一个选民的年龄,在我的实体中,我创建了一个这样的函数//voters.phppublicfunctiongetAge(){$birthday=$this->birthday;$age=date_diff(date_create($birthday),date_create('today'))->y;return$age;}我像这样在Twig中渲染它{{entity.getAge()}}但是显示如下错误:"Anexceptionhasbeenthrownduringtherenderingofatemplate("Warning:date_create()expect

php - 使用 ini_set() 的 PSR-1 兼容替代方案是什么?

我正在使我的代码库符合PSR-2标准(因此符合PSR-1标准),我遇到了以下代码:publicfunctioninit(){parent::init();//AllowALargerPHPMemoryLimitForThisScriptini_set("memory_limit","512M");//AllowALargerScriptExecutionLimitForThisScriptini_set('max_execution_time',300);}用于增加此特定脚本(仅供站点管理员访问且不经常运行)能够消耗的内存量和执行时间。在php.ini中设置默认的memory_limi

php - codeception : Setting the "doctrine" pre-defined service is deprecated since Symfony 3. 3 并且 Symfony 4.0 将不再支持

我的项目是一个带有DoctrineORM的Symfony3.3.9项目。我将codeception2.3.6与模块Doctrine2一起使用,我关注这篇文章:http://codeception.com/docs/modules/Doctrine2我的codeception配置是:#tests/functional.suite.ymlactor:FunctionalTestermodules:enabled:-\Helper\Functional-PhpBrowser:url:http://localhost-Symfony-Doctrine2:depends:Symfonyclean

php - strftime() 和 gmstrftime() 返回 "%s"的错误结果

PHP函数strftime()和gmstrftime()返回格式为"%s"的(不同的)错误结果。我使用CLI和Apache(OpenSuse)使用PHP5.5.14和PHP7.2.5对其进行了测试。我使用带和不带DST的时间戳。我的问题:你能用其他版本/系统确认这个错误吗?测试脚本错误的结果%s应该返回原始时间戳,但它没有。结果相差1小时(3600秒)。date_default_timezone_set('UTC')15463036001546300000,2019-01-0100:46:40UTC我已经向bugs.php.net报告了这个错误:https://bugs.php.net

php - __get() 和 __set() 的最佳实践

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。源于此question关于使用__get()和__set()访问私有(private)变量,我想了解一下它们的一般使用方式。我想知道何时何地是使用重载函数的最佳时机,以及您在哪里使用过重载函数(如果有的话)。为了清楚起见,我们正在谈论这些功能:http://us2.php.net/manual/en/language.oop5.magic.php

php __get() 和 __set() 魔术的要点

PHP5引入了魔术方法__get()和__set()。根据我的理解,这是必须编写每个成员的getter和setter的捷径;$var=$name;}function__get($var){return$this->$var;}}$person=newPerson();$person->firstname="Tom";$person->lastname="Brady";echo$person->firstname."".$person->lastname;//print:TomBrady?>我的问题是,这就像公开成员变量一样。classPerson{public$firstname;pu

php - Zend_Cache - "Datas must be string or set automatic_serialization = true"

我正在尝试像这样使用Zend_Cache缓存一个数组:$cache=Zend_Registry::get('cache');//$dataisanarray$cache->save($data,'externalData');我收到这个错误:Message:Datasmustbestringorsetautomatic_serialization=true即使在引导文件中初始化Zend_Cache时automatic_serialization设置为真:protectedfunction_initCache(){$frontend=array('lifetime'=>7200,'aut

php - PHP函数date()的反义词是什么?

PHP中是否有任何函数可以获取日期并将其转换为时间戳,或者可以简单地获取一种格式的日期并将其更改为另一种格式?我有一组格式为“md”的日期,我想将其更改为“l,Fd,Y”。我还需要它和其他格式的日期,所以我需要一个函数,让我给它一个日期、输入格式和输出格式。 最佳答案 试试strtotime(http://www.php.net/strtotime) 关于php-PHP函数date()的反义词是什么?,我们在StackOverflow上找到一个类似的问题: h