我正在使用magento 1.7.2,我想添加日期属性和时间,这样可以保存日期以及数据库中该产品的时间.
我试过这个代码在我的模块中使用mysql-setup文件添加新属性.
$setup->addAttribute('catalog_product', 'new_date', array(
'group' => 'General',
'input' => 'date',
'type' => 'datetime',
'label' => 'New Date',
'backend' => 'eav/entity_attribute_backend_datetime',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 1,
'filterable' => 1,
'comparable' => 1,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
Run Code Online (Sandbox Code Playgroud)
但这只给我选择时间的日期.
请帮我.
谢谢.
我试图获得两天之间的时差.但是对于某些日期/时间,我得到了错误的答案
这是我的代码:
/****************************************
$start_date = new DateTime('23:58:40'); *These two still give
$end_date = new DateTime('00:00:00'); *a wrong answer
*****************************************/
$start_date = new DateTime('23:58:40');
$end_date = new DateTime('00:11:36');
$dd = date_diff($end_date, $start_date);
//Giving a wrong answer: Hours = 23, Minutes = 47, Seconds = 4
echo "Hours = $dd->h, Minutes = $dd->i, Seconds = $dd->s";
Run Code Online (Sandbox Code Playgroud) 我尝试升级我的自定义Magento模块但由于某种原因它无法正常工作.
我的模块配置:
<?xml version="1.0"?>
<config>
<modules>
<MVE_CategoryAttribute>
<version>0.1.1</version>
</MVE_CategoryAttribute>
</modules>
<global>
<resources>
<categoryattribute_setup>
<setup>
<module>MVE_CategoryAttribute</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
<connection>
<use>default_setup</use>
</connection>
</categoryattribute_setup>
</resources>
</global>
</config>
Run Code Online (Sandbox Code Playgroud)
安装脚本(mysql4-install-0.1.0.php):
<?php
$this->startSetup();
$this->addAttribute('catalog_category', 'imagetext', array(
'group' => 'General Information',
'input' => 'textarea',
'type' => 'varchar',
'label' => 'Tekst op afbeelding',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
?>
Run Code Online (Sandbox Code Playgroud)
升级脚本(mysql4-upgrade-0.1.0-0.1.1.php):
<?php
$this->startSetup();
$this->updateAttribute('catalog_category', 'imagetext', 'global', Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE);
$this->endSetup();
?>
Run Code Online (Sandbox Code Playgroud) 如何获取count函数返回的列的名称
这是问题所在
cypherquery='START n=node:node_auto_index(name='Ashish') MATCH n-[:f]-h RETURN h,count(h)'
Run Code Online (Sandbox Code Playgroud)
第一列名称肯定'h'但是第二列的名称呢?
我有一个reg exp,它应该检查名称中是否有任何非法字符.允许的字符是0-9,az,AZ,middlescore( - )和下划线(_).
这是功能
function validate_playername($playername){
if (preg_match('/^[0-9A-Z-_]$/i',$playername)) {
return true;
} else{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这个函数就是这样调用的
if (validate_playername($addplayer)) {
echo "valid player Name";
} else {
echo "Invalid Player Name";
}
Run Code Online (Sandbox Code Playgroud)
但是,当我输入像velocity28这样的正确名称时,它将返回无效的播放器名称.我的reg错了吗?
在下面的PHP代码中,我试图回显$ title和$ desc的值,但它不显示仅显示变量名称的值.任何帮助将不胜感激.
foreach ($prod as $product) {
$title=$product['title'];
$desc=$product['desc'];
echo '
<div class="detail">
<div class="img"><img src="images/pro1.png"/></div>
<div class="textdetail"><p><b>$title</b><br /></p>
<p><a href="#">$desc</a></p>
</div><br />
</div>';
}
Run Code Online (Sandbox Code Playgroud) 我有一个字段,如果满足特定条件,则该字段具有自定义文本...如果不满足,则该字段为空白。
我已经编写了一个自定义函数测试是否设置了变量
function AmISet($fieldName) {
if (isset($fieldName)) {
echo "I am set";
}else{
echo "I am not set";
}
};
Run Code Online (Sandbox Code Playgroud)
但是当我附加该字段时,出现变量未定义的错误。但当我做常规时,isset($fieldName);
我没有问题。有什么方法可以解决这个问题并让我的函数而不是 isset() 执行此操作?
我想在函数中添加其他逻辑,但我只希望它在设置变量的情况下工作......但如果没有设置变量,我不希望出现未定义的错误。
我是 php 新手,非常感谢您能给我的任何帮助或指导。感谢您的帮助!