这是有问题的代码:
来自index.php:
require_once('includes/DbConnector.php');
// Create an object (instance) of the DbConnector
$connector = new DbConnector();
// Execute the query to retrieve articles
$query1 = "SELECT id, title FROM articles ORDER BY id DESC LIMIT 0,5";
$result = $connector->query($query1);
echo "vardump1:";
var_dump($result);
echo "\n";
/*(!line 17!)*/ echo "Number of rows in the result of the query:".mysql_num_rows($result)."\n";
// Get an array containing the results.
// Loop for each item in that array
while ($row = $connector->fetchArray($result)){
echo '<p> <a href="viewArticle.php?id='.$row['id'].'">';
echo $row['title']; …
Run Code Online (Sandbox Code Playgroud) 致命错误:在第103行的/home/ssmagnet/public_html/lib/Zend/Locale/Format.php中,耗尽了33554432字节的允许内存大小(尝试分配30720字节)
请帮我解决这个问题
我不得不在添加产品时自动添加自定义选项,代码工作正常,但我需要创建一个带有选项的下拉菜单,我不知道如何添加选项到创建的下拉列表,我的代码是
public function Add_CustomOptions_Automatically($observer) {
$product = $observer->getEvent()->getProduct();
$save = false; if (!$product->getOptions()) $save = true;
$optionData = array(
'previous_group' => 'text',
'title' => 'Size',
'type' => 'drop_down',
'is_require' => 0,
'sort_order' => 0,
'price' => 0,
'price_type' => 'fixed');
if($save):
$product->setHasOptions(1)->save();
$option = Mage::getModel('catalog/product_option')
->setProductId($product->getId())
->setStoreId($product->getStoreId())
->addData($optionData);
$option->save();
$product->addOption($option);
endif;
}
Run Code Online (Sandbox Code Playgroud)
}
我已创建,'type' => 'drop_down'
但如何添加选项?我不知道如何添加选项,任何帮助将非常感激.
谢谢,
情况如下:
我想在Magento后端导航菜单中添加一个菜单.
我通过添加以下代码完成了这个app/etc/config.xml
:
<adminhtml>
<menu>
<example translate="title" module="adminhtml">
<title>Inventory</title>
<sort_order>110</sort_order>
<children>
<set_time>
<title>Set It!</title>
<action>helloworld/index/goodbye</action>
</set_time>
</children>
</example>
</menu>
Run Code Online (Sandbox Code Playgroud)
问题是我无法在权限 - >角色资源中包含此菜单,因此我无法将其分配给特定用户.
如何在权限 - >角色资源中包含此菜单?
谢谢你,更有力量!
我有配置问题或magento永远不会运行我的模块的SQL安装/更新脚本的其他东西!
我使用magento-1.4.1.0
这是我的结构文件夹和文件:
\app\code\local\RN\ShortUrl
\app\code\local\RN\ShortUrl\Block\ShortUrl.php
\app\code\local\RN\ShortUrl\controllers\IndexController.php
\app\code\local\RN\ShortUrl\controllers\UController.php
\app\code\local\RN\ShortUrl\etc\config.xml
\app\code\local\RN\ShortUrl\Helper\Url.php
\app\code\local\RN\ShortUrl\Model\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl.php
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl\Collection.php
\app\code\local\RN\ShortUrl\Model
\app\code\local\RN\ShortUrl\Model\Mysql4
\app\code\local\RN\ShortUrl\Model\Mysql4\ShortUrl
\app\code\local\RN\ShortUrl\sql\rn_shorturl_setup\mysql4-install-0.1.0.php
Run Code Online (Sandbox Code Playgroud)
以下是内容\app\etc\modules\RN_ShortUrl.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<RN_ShortUrl>
<active>true</active>
<codePool>local</codePool>
</RN_ShortUrl>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)
以下是内容\app\code\local\RN\ShortUrl\etc\config.xml
:
<?xml version="1.0"?>
<config>
<modules>
<RN_ShortUrl>
<version>0.1.0</version>
</RN_ShortUrl>
</modules>
<frontend>
<routers>
<shorturl>
<use>standard</use>
<args>
<module>RN_ShortUrl</module>
<frontName>shorturl</frontName>
</args>
</shorturl>
</routers>
<layout>
<updates>
<shorturl>
<file>shorturl.xml</file>
</shorturl>
</updates>
</layout>
</frontend>
<global>
<blocks>
<rn_shorturl>
<class>RN_ShortUrl_Block</class>
</rn_shorturl>
</blocks>
<rewrite>
<rn_shorturl>
<from>#^/u/(.*)#</from>
<to>/shorturl/u/redirect/key/$1</to>
</rn_shorturl>
</rewrite>
<models>
<shorturl>
<class>RN_ShortUrl_Model</class>
<resourceModel>shorturl_mysql4</resourceModel>
</shorturl>
<shorturl_mysql4>
<class>RN_ShortUrl_Model_Mysql4</class>
<entities>
<shorturl> …
Run Code Online (Sandbox Code Playgroud) 我正在写一个Observer来管理订单的项目,我需要根据一些自定义属性为每个订单发送一封电子邮件.
item对象是Mage_Sales_Model_Order_Item并且搜索我尝试过getData('my_code'),getCustomAttribute,getAttributeText等方法但没有成功.
我需要获取类别,大小,颜色和一些自定义属性......这里是我的小代码
class Example_OrderMod_Model_Observer{
public function doSomething($observer){
$order = $observer->getEvent()->getOrder();
$id_ordine = $order->getRealOrderId();
$cliente = $observer->getEvent()->getOrder()->getCustomerName();
foreach ($order->getAllItems() as $item) {
//$item is an instance of Mage_Sales_Model_Order_Item
$quantita = $item->getQtyOrdered();
$codice_giglio = $item->getSku();
//echo $item->getData('size');
var_dump($item->getAttributeText('size'));
var_dump($item->getProductOptionByCode('size'));
var_dump($item->getProductOptionByCode('famiglia'));
}
// die();
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
非常感谢
我的模块中的Magento翻译有点问题,因为它不起作用.正如所有教程所说的那样应该很容易.每个app/locale/[xx_XX]/ - 文件夹中都有一个.csv文件,在config.xml中也有一个条目.我的模块中有一个帮助器,它也在config.xml中注册,我可以使用它.毕竟,我清除了所有缓存文件并再次尝试.
我错了什么或忘记了什么?
代码中的调用:
$str = Mage::helper('mymodule')->__('mystring');
Run Code Online (Sandbox Code Playgroud)
在config.xml中(在前端,adminhtml和全局命名空间中尝试了这个块):
<translate>
<modules>
<Namespace_Module>
<files>
<default>Namespace_Module.csv</default>
</files>
</Namespace_Module>
</modules>
</translate>
Run Code Online (Sandbox Code Playgroud) 我正在升级我的Rails 5应用程序,目前正在克服以下弃用:
DEPRECATION WARNING: `redirect_to :back` is deprecated and will be removed from Rails 5.1. Please use `redirect_back(fallback_location: fallback_location)` where `fallback_location` represents the location to use if the request has no HTTP referer information. (called from block (3 levels) in <top (required)> at /path/to/some/controller_spec.rb:74)
Run Code Online (Sandbox Code Playgroud)
别担心.刚刚将控制器切换到新格式:
redirect_back(fallback_location: home_path, message: "Some error")
Run Code Online (Sandbox Code Playgroud)
但是,警告不会消失,因为测试仍然会看到:back
,如下所示:
expect(response).to redirect_to(:back)
Run Code Online (Sandbox Code Playgroud)
我没有看到任何克服这种弃用的首选方法.有没有其他方法来测试这个,而无需HTTP_REFERER
在我的测试中手动指定?
我有一个看起来像这样的ElasticSearch索引:
{
"mappings": {
"article": {
"properties": {
"title": { "type": "string" },
"tags": {
"type": "keyword"
},
}
}
}
Run Code Online (Sandbox Code Playgroud)
和看起来像这样的数据:
{ "title": "Something about Dogs", "tags": ["articles", "dogs"] },
{ "title": "Something about Cats", "tags": ["articles", "cats"] },
{ "title": "Something about Dog Food", "tags": ["articles", "dogs", "dogfood"] }
Run Code Online (Sandbox Code Playgroud)
如果我搜索dog
,我会得到第一个和第三个文件,正如我所期望的那样.而且我可以按照自己喜欢的方式对搜索文档进行加权(实际上,我正在使用一个function_score
查询来衡量一堆与此问题无关的字段).
什么我喜欢做的排序是tags
场让最相关的标签首先返回,而不会影响文件本身的排序顺序.所以我希望得到这样的结果:
{ "title": "Something about Dog Food", "tags": ["dogs", "dogfood", "articles"] }
Run Code Online (Sandbox Code Playgroud)
而不是我现在得到的:
{ "title": "Something about Dog …
Run Code Online (Sandbox Code Playgroud)