我正在尝试将EWZRecaptcha添加到我的注册表单中.我的注册表单构建器看起来像这样:
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('username', 'text')
->add('password')
->add('recaptcha', 'ewz_recaptcha', array('property_path' => false));
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Acme\MyBundle\Entity\User',
);
}
Run Code Online (Sandbox Code Playgroud)
现在,我如何将Recaptcha约束添加到验证码字段?我试着把它添加到validation.yml:
namespaces:
RecaptchaBundle: EWZ\Bundle\RecaptchaBundle\Validator\Constraints\
Acme\MyBundle\Entity\User:
...
recaptcha:
- "RecaptchaBundle:True": ~
Run Code Online (Sandbox Code Playgroud)
但我得到Property recaptcha does not exists in class Acme\MyBundle\Entity\User
错误.
如果我array('property_path' => false)
从recaptcha字段的选项中删除,我会收到错误:
Neither property "recaptcha" nor method "getRecaptcha()" nor method "isRecaptcha()"
exists in class "Acme\MyBundle\Entity\User"
Run Code Online (Sandbox Code Playgroud)
知道怎么解决吗?:)
我有一个关于在Zend上传文件后重命名文件的问题.我不知道在哪里放置重命名过滤器.这就是我所拥有的.我试过搬东西,但我迷路了.目前它确实将文件上传到我的照片文件夹,但它没有重命名.谢谢你的帮助!
if($this->_request->isPost())
{
$formData = $this->_request->getPost();
if ($form->isValid($formData))
{
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination(WWW_ROOT . '/photos');
$photo = $adapter->getFileInfo('Photo');
$adapter->addFilter('Rename', array(
$photo['Photo']['tmp_name'],
WWW_ROOT . '/photos/' . $this->memberId . '.jpg',
true
));
if ($adapter->receive())
{
echo 'renamed';
}
}
}
Run Code Online (Sandbox Code Playgroud) 我注意到很多人在讨论Gearman及其调度功能,使其能够将工作分配到其他服务器上.但是,我还没有看到与本机cronjobs的比较.
cron和Gearman有什么区别?
是否可以在ESI与Symfony 2中使用验证缓存?
如果查看HttpFoundation Response类,可以看到isNotModified的工作原理:
/**
* Determines if the Response validators (ETag, Last-Modified) match
* a conditional value specified in the Request.
*
* If the Response is not modified, it sets the status code to 304 and
* removes the actual content by calling the setNotModified() method.
*
* @param Request $request A Request instance
*
* @return Boolean true if the Response validators match the Request, false otherwise
*
* @api
*/
public function isNotModified(Request $request) …
Run Code Online (Sandbox Code Playgroud) 当我需要仅计算08:00:00-16:00:00之间的时间时,计算从MySQL获取的两个日期时间值之间的时间的最佳方法是什么.
例如,如果我有值2008-10-13 18:00:00和2008-10-14 10:00:00,则时差应为02:00:00.
我可以用SQL做什么或者最好的方法是什么?我正在建立一个网站并使用PHP.
谢谢您的回答.
编辑:确切的是,我正在尝试计算"票"在工作时间内处于特定状态的时间.时间可能是几个星期.
EDIT2:我没有计算实际时差的问题,但减去了关闭时间,每天00:00:00-08:00:00和16:00:00-00:00:00.
-Samuli
我有一个扩展Zend_Form这样的类(简化):
class Core_Form extends Zend_Form
{
protected static $_elementDecorators = array(
'ViewHelper',
'Errors',
array('Label'),
array('HtmlTag', array('tag' => 'li')),
);
public function loadDefaultDecorators()
{
$this->setElementDecorators(self::$_elementDecorators);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我使用该类创建所有表单:
class ExampleForm extends Core_Form
{
public function init()
{
// Example Field
$example = new Zend_Form_Element_Hidden('example');
$this->addElement($example);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的一种观点中,我只需要显示这一字段(Zend_Form不会生成任何其他内容)。所以我认为我有:
<?php echo $this->exampleForm->example; ?>
Run Code Online (Sandbox Code Playgroud)
这工作正常,除了它会生成如下所示的字段:
<li><input type="hidden" name="example" value=""></li>
Run Code Online (Sandbox Code Playgroud)
这显然是因为我将元素装饰器设置为包括HtmlTag:tag =>'li'。
我的问题是:如何禁用此元素的所有装饰器。隐藏的输入元素不需要装饰器。
我正在编写一个自定义验证器,用于检查至少有一个字段是否有值.我想验证'namefield'或'idfield'是否有值.其中一个可以是空的,或者两个都可以有值,但至少其中一个必须有值.
$nameField = new Zend_Form_Element_Hidden('namefield');
$nameField->setValue($this->nameFieldValue)
->addValidator('AtLeastOneHasValue', false, array('idfield'));
Run Code Online (Sandbox Code Playgroud)
根据我的理解,除非我将表单元素设置为required,否则我的验证器将不会验证.
->setRequired(true)
Run Code Online (Sandbox Code Playgroud)
但是,如果我将其设置为required,它会自动验证它是否为空,并且错误消息显示它为空.我想允许该字段为空,并使用我的自定义验证器验证多个字段.如何使用自定义验证器验证表单元素,而不将表单元素设置为必需?
我正在尝试保存元素的背景图像,删除它然后可能稍后再添加它.
var current_bg_image = $("#div").css("background-image");
if(something){
$("#div").css("background-image", "none");
}else{
$("#div").css("background-image", current_bg_image); // not working...
}
Run Code Online (Sandbox Code Playgroud)
添加了背景图像是应该的部分回不工作......但是,如果我改变current_bg_image
与"url(something.jpg)"
它的工作原理.似乎css()不适用于变量?
我已经好好看看了,但我无法弄清楚如何在Magento Enterprise Edition中获得和设置奖励积分
我该怎么做这样的事情:
$customer = Mage::getModel('customer/customer')->load($customer_id);
Mage::getModel('enterprise_reward/reward')->setPoints($customer, $points);
$points = Mage::getModel('enterprise_reward/reward')->getPoints($customer);
Run Code Online (Sandbox Code Playgroud) 在我的一个Git项目中,我有md5
格式化的文件,我想忽略它.
我试着将以下条目添加到我的.gitignore
,
[0-9a-f]{32}
Run Code Online (Sandbox Code Playgroud)
但显然.gitignore
文件不支持regexp.是否有相同的方法来实现这一目标?
我在我的网站上使用tinyMCE作为我的文本编辑器,我想在将文本保存到我的数据库之前重新格式化文本(将’标签更改为'然后更改为').我找不到使用tinyMCe这样做的简单方法,并使用htmlentities()更改包括<>在内的所有内容.有任何想法吗?