小编bei*_*lex的帖子

无法删除301重定向

我愚蠢地在websiteA.com上进行了301重定向到websiteB.com.从.htaccess文件中删除它后,重定向仍在运行.我尝试从本地网络外部进行重定向.我已清除缓存并尝试使用其他浏览器.

有人有什么建议吗?

更新:

如果我向此.htaccess文件添加302重定向,该网站将尊重它.当我删除它时,仍然会发生旧的301重定向.

.Ataccess文件为websiteA.com:

# -- concrete5 urls start --

Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# -- concrete5 urls end --

#RewriteCond %{HTTP_HOST} ^.*$
#RewriteRule ^/?$ "http\:\/\/www\.websiteB\.co\.uk\/" [R=301,L]
Run Code Online (Sandbox Code Playgroud)

.htaccess redirect http-status-code-301

13
推荐指数
5
解决办法
2万
查看次数

NaN在Javascript字符串连接中

拿这个数组:

errors [
    "Your name is required.", 
    "An email address is required."
]
Run Code Online (Sandbox Code Playgroud)

我试图迭代它并创建一个字符串,如:

"Your name is required.\nAn email address is required.\n"
Run Code Online (Sandbox Code Playgroud)

使用此代码:

var errors = ["Your name is required.","An email address is required."];

if (errors) {

    var str = '';

    $(errors).each(function(index, error) {
        str =+ error + "\n";
    });

    console.log(str); // NaN

}
Run Code Online (Sandbox Code Playgroud)

我正在进入NaN控制台.为什么这样,我该如何解决?

提前致谢.

javascript

8
推荐指数
2
解决办法
5795
查看次数

如何使用Modernizr和YesNope Javascript检查FormData

如何使用ModernizrYepNope检查FormData对象?

<script>
yepnope({  
  test : what.to.check,  
  yep  : 'normal.js',  
  nope : 'flashupload.js'  
});      
</script>
Run Code Online (Sandbox Code Playgroud)

javascript modernizr yepnope

5
推荐指数
1
解决办法
3049
查看次数

HTML5结构和章节或文章中的标题

虽然我真的应该知道这一点,但我担心我不能完全理解.阅读过不同的文章,阅读书籍并与其他人交谈后,我仍然不太了解HTML5的正确结构section.h1在每个section和/或中都有一个标签是否合适article?是否新的sectionarticle构成开始h1h2再次处理?

我的印象是每个"块"应该被允许它自己的"标题"结构.

例如,这是正确的HTML5吗?:

<!doctype html>
<html>
  <head>
    <title>
    <!-- etc. etc. -->

    <body>
      <section> <!-- two or more <articles> within this section, both using <h1> tags -->
        <h1>Here is a section with articles in</h1>
        <article>
          <h1>Heading</h1>
          <h2>sub heading</h2>
          <p>A paragraph>
        </article>
        <article>
          <h1>Heading</h1>
          <h2>sub heading</h2>
          <p>A paragraph</p>
        </article>
        ...      
      </section>
      <section> <!-- two or more <articles> within this additional section, both using <h1> tags …
Run Code Online (Sandbox Code Playgroud)

html5

5
推荐指数
1
解决办法
269
查看次数

不要在 magento 中使用“平面”数据

读过Alan Storm 的Fixing Magento Flat Collections with Chaos并在这里找到类似的问题后,我试图返回属于某个类别但不使用 Magento 的“平面”数据的产品。

这是我最初使用的代码:

        $category_model = Mage::getModel('catalog/category')->load($cid);
        $collection = Mage::getModel('catalog/product_collection');
        $collection->addCategoryFilter($category_model);
        $collection->addAttributeToSort('entity_id','DESC'); 
        $collection->addAttributeToSelect('*');

        $collection->printLogQuery(true);
Run Code Online (Sandbox Code Playgroud)

当通过 AJAX 触发此代码时,我得到的结果与从观察者运行它时得到的结果不同,原因是平面数据。所以我编写了自己的类来使用 EAV 模型:

app/code/local/Mynamespace/Mymodule/Model/Category.php:

class Mynamespace_Mymodule_Model_Category extends Mage_Catalog_Model_Category
{
    protected function _construct()
    {

        $this->_init('catalog/category');

    }

}
Run Code Online (Sandbox Code Playgroud)

和:

app/code/local/Mynamespace/Mymodule/Model/Productcollection.php:

class Mynamespace_Mymodule_Model_Productcollection 
extends Mage_Catalog_Model_Resource_Product_Collection
{
    protected function _construct()
    {

        $this->_init('catalog/product');
        $this->_initTables();
    }

}
Run Code Online (Sandbox Code Playgroud)

然后更改我的查询代码:

        $category_model = Mage::getModel('mymodule/category')->load($cid);
        $collection = Mage::getModel('mymodule/productcollection');
        $collection->addCategoryFilter($category_model);
        $collection->addAttributeToSort('entity_id','DESC'); 
        $collection->addAttributeToSelect('*');

        $collection->printLogQuery(true);
Run Code Online (Sandbox Code Playgroud)

然而上面的代码仍然查询平面数据表。我可能做错了什么?

magento

5
推荐指数
1
解决办法
4820
查看次数

如何使用jQuery获取数组键名?

我有一个这样的数组:

var myArray = new Array();

myArray['foo'] = {
    Obj: {
        key: value
    }
};
myArray['bar'] = {
    Obj: {
        key: value
    }
};
Run Code Online (Sandbox Code Playgroud)

当我这样做时,console.log(myArray)我只是变空了[ ]。当我尝试使用 jQuery 迭代数组时,each该函数不会运行。

如何获取数组的“foo”和“bar”部分?

示例代码:

console.log(myArray); // [ ]

jQuery.each(myArray, function(key, obj) {
    console.log(key); // should be 'foo' following by 'bar'
});
Run Code Online (Sandbox Code Playgroud)

此外,为什么这样做:

jQuery.each(myArray[foo], function(obj, values) {

    // Why does this work if there are no associative arrays in JS?

});
Run Code Online (Sandbox Code Playgroud)

javascript arrays jquery

5
推荐指数
1
解决办法
3万
查看次数

z-index 相对定位元素下的绝对定位元素

我试图将绝对定位的元素放在相对定位的元素下。由于场地开发的限制,蓝框必须相对定位。

想象一个语音气泡是蓝色框,气泡的尾部是 :after 伪元素。我需要绿框在这两个后面,因为它是为这两个元素保留背景。

div.layer01 {
    background-color: blue;
    position: relative;
    z-index: 10;
}
div.layer01:after {  /* This is the tail of the bubble */
    display: block;
    background-color: red;
    content: '\00a0';
    width: 30px;
    height: 30px;
    position: absolute; 
    right: 20px;
    top: 50px;
    border: 3px #fff solid;
}    

/* This should be behind the tail and the blue box (bubble) */
div.layer01 div.layer02 { 
    background-color: green;
    width: 320px;
    height: 125px;
    display: block;
    position: absolute; 
    z-index: 5;
}
Run Code Online (Sandbox Code Playgroud)
<div class="layer01"> <!-- speech bubble --> …
Run Code Online (Sandbox Code Playgroud)

css z-index css-position

4
推荐指数
1
解决办法
1万
查看次数

Javascript字符串替换(更优雅的方式)

我有一个字符串:

var myString = 'Some text {{more text}} next text';
Run Code Online (Sandbox Code Playgroud)

我正在尝试替换{{}}使用<span></span>.

我做了这样做:

var myString = 'Some text {{more text}} next text';
myString = myString.replace(/\{\{/, '<span>');
myString = myString.replace(/\}\}/, '</span>');
console.log(myString);
Run Code Online (Sandbox Code Playgroud)

然而这看起来很混乱,有没有更优雅的方法?

javascript

3
推荐指数
1
解决办法
84
查看次数

Laravel - 作业报告失败(即使它正确退出)

我正在使用最新版本的 Homestead。我也设置了 Laravel Horizo​​n。我使用 Redis 作为队列驱动程序。Laravel 是 5.6 版,是全新安装的。

发生的事情是我的工作都失败了(即使工作正确退出)。

我使用自定义命令通过命令行运行作业:

vagrant@homestead:~/myapp$ artisan crawl:start
vagrant@homestead:~/myapp$ <-- No CLI errors after running
Run Code Online (Sandbox Code Playgroud)

应用程序/控制台/命令/crawl.php

<?php

namespace MyApp\Console\Commands;

use Illuminate\Console\Command;
use MyApp\Jobs\Crawl;

class crawl extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'crawl:start';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Start long running job.';

    /**
     * Create a new command instance.
     *
     * …
Run Code Online (Sandbox Code Playgroud)

php queue laravel laravel-horizon

3
推荐指数
1
解决办法
3536
查看次数

使用DOMDocument和DOMXPath迭代元素

我试图遍历包含的每个子元素div:

$html = '    <div id="roothtml">
<h1>
Introduction</h1>
<p>text</p>
<h2>
text</h2>
<p>
test</p>
</div>';
Run Code Online (Sandbox Code Playgroud)

我有这个PHP:

$dom = new DOMDocument();
$dom->loadHTML($html);

$dom->preserveWhitespace = false;

$xpath = new DOMXPath($dom);
$els = $xpath->query("/div");
print_r($els);   
Run Code Online (Sandbox Code Playgroud)

我得到的只是 DOMNodeList Object ( )

看了IBM教程后我应该得到一个数组.我做错了什么?

任何帮助表示赞赏.

php xpath dom

2
推荐指数
1
解决办法
1857
查看次数

在Magento中为类别编辑页面添加额外的选项卡

我正在尝试在类别编辑页面的顶部添加一个额外的选项卡.默认值为:常规信息,显示设置,自定义设计和类别产品.

所以我创建了一个新模块来重写生成选项卡的块.以下是config.xml的相关代码段:

    <blocks>

        <adminhtml>

            <rewrite>

                <catalog_category_tabs>

                    MyNamespace_MyModule_Block_Catalog_Category_Tabs

                </catalog_category_tabs>

            </rewrite>

        </adminhtml>

    </blocks>
Run Code Online (Sandbox Code Playgroud)

这是我的块覆盖默认的Magento:

class MyNamespace_MyModule_Block_Catalog_Category_Tabs extends Mage_Adminhtml_Block_Catalog_Category_Tabs
{

    protected function _prepareLayout()
    {
        $categoryAttributes = $this->getCategory()->getAttributes();
        if (!$this->getCategory()->getId()) {
            foreach ($categoryAttributes as $attribute) {
                $default = $attribute->getDefaultValue();
                if ($default != '') {
                    $this->getCategory()->setData($attribute->getAttributeCode(), $default);
                }
            }
        }

        $attributeSetId     = $this->getCategory()->getDefaultAttributeSetId();
        /** @var $groupCollection Mage_Eav_Model_Resource_Entity_Attribute_Group_Collection */
        $groupCollection    = Mage::getResourceModel('eav/entity_attribute_group_collection')
            ->setAttributeSetFilter($attributeSetId)
            ->setSortOrder()
            ->load();
        $defaultGroupId = 0;
        foreach ($groupCollection as $group) {
            /* @var $group Mage_Eav_Model_Entity_Attribute_Group */
            if ($defaultGroupId == 0 or $group->getIsDefault()) …
Run Code Online (Sandbox Code Playgroud)

magento

0
推荐指数
1
解决办法
3597
查看次数