小编bes*_*rld的帖子

从CodeIgniter中的不同表中删除行

一点代码片段:

$this->db->where('id', $outfit_id);
$this->db->update('outfit_main',$data);

//Delete productsettings for specific outfit (They are added below with new values)
$this->db->where('outfit_id', $outfit_id);
$this->db->delete('outfit_products');

//Delete outfit_images for specific outfit as well. They are also added below
$this->db->where('outfit_id', $outfit_id);
$this->db->delete('outfit_images'); 
Run Code Online (Sandbox Code Playgroud)

我想做的是:

  1. 从outfit_main中删除行,其中id = $ outfit_id
  2. 从outfit_products中删除行,其中outfit_id = $ outfit_id
  3. 从outfit_images中删除行,其中outfit_id = $ outfit_id

但实际上当我添加最后两行时:

$this->db->where('outfit_id', $outfit_id);
$this->db->delete('outfit_images'); 
Run Code Online (Sandbox Code Playgroud)

*它也会删除outfit_main中的所有行.为什么?*

php activerecord codeigniter

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

是否可以在运行时更改 max_input_vars?

在巨大的表单中存在表单元素数量的问题。帖子中未包含某些元素。

经过一番搜索,我看到了这个: $_POST max array size

$this->input->post('formelement') uses max_input_vars as limiter.
Run Code Online (Sandbox Code Playgroud)

上面链接的回答没问题。我知道我必须max_input_vars在 php.ini 中使用。这在本地没问题,但是如果我的生产服务器的网络托管公司不允许我在他们的服务器上更改此设置 - 这不是一个选项。

我正在使用 codeIgniter 并创建一个这样的表单:

<?php        
$attributes = array('id' => 'id of form');
echo form_open('controller/function-name', $attributes);
//actual form content
echo form_close();
?>
Run Code Online (Sandbox Code Playgroud)

进一步阅读后,我明白我可以http://input用来绕过这个 max_input_var 限制。

我可以通过这样做来获得原始数据输出 controller/function-name

$postdata = file_get_contents("php://input"); 
Run Code Online (Sandbox Code Playgroud)

但是随后我将不得不手动检查 csrf 值等,填充 postdata,正确地分解它等等......

我也在 htaccess 中尝试过:(基于PHP 5.2.17 中的 max_input_vars 限制

RewriteEngine On
RewriteBase /
php_value max_input_vars 6000
php_value suhosin.post.max_vars 6000
php_value suhosin.request.max_vars 6000
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} …
Run Code Online (Sandbox Code Playgroud)

php forms codeigniter input

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

使用imagerotate()旋转图像后如何获得新的宽度和高度?

如何实际获得旋转图像后设置的新宽度和高度?

$ps['product_angle'] = 77; //Could be any angle
$filename = 'test.png'     //filename to the original product

list($source_width, $source_height) = getimagesize($filename);
$source_image = imagecreatefromjpeg($filename);         
$angle = $ps['product_angle'];
if (intval($angle) <> 0) {
    $source_image = imagerotate($source_image, 360-$angle, imageColorAllocateAlpha($source_image, 255, 255, 255, 127));
}

$ps['source_image'] = $source_image;
Run Code Online (Sandbox Code Playgroud)

我想要这个,因为我想根据上面创建的图像调整图像大小.($ps['source_image'])

//If I do an image 
list($source_width, $source_height) =     getimagesize($filename);

$dest_width = (int)$ps['product_width'];
$dest_height = (int)$ps['product_height'];

//Resize source-image to new width and height
//But this width and height are incorrect because they are 
//set …
Run Code Online (Sandbox Code Playgroud)

php

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

新的Wp_Query()或pre_get_posts()来查看自定义帖子类型的所有帖子?

我有一个存档模板文件,显示自定义帖子类型人员的所有帖子(称为archive-personnel.php):

这是文件的开头......

<?php 
get_header(); 

//Show all posts for this custom posttype (personnel)
$args = array( 'post_type' => 'personnel', 'posts_per_page' => -1 );
$personnel_query = new WP_Query( $args );
if (have_posts()) : while ($personnel_query->have_posts()) : $personnel_query->the_post(); 
Run Code Online (Sandbox Code Playgroud)

这是有效的,但我知道我也可以使用pre_get_posts().但是pre_get_posts()- 使用- 过滤器,你必须检查它是否影响管理员等.

所以我的问题是:我使用哪种替代方案或只是偏好/品味的问题真的很重要吗?

wordpress custom-post-type

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

是否可以在一个调用中从数组更新post meta?

程式码片段:

$save_dbarray = array(
    'email'         => 'email@email.se',
    'adress'        => 'adress'
);

//Save values from created array into db
foreach($save_dbarray as $meta_key=>$meta_value) {
   update_post_meta($post_id, $meta_key, $meta_value);
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以优化上面的代码?在这种简单的情况下,没关系,但是如果我的阵列很大,那么我猜更新时可能是性能问题?

我想做类似的事情:

update_post_meta($post_id, $save_dbarray);
Run Code Online (Sandbox Code Playgroud)

这可能吗?

wordpress optimization updates

3
推荐指数
2
解决办法
9716
查看次数

如何使用 bcmath 以好的方式添加许多值?

如果我想将多个值与 BCMath 一起添加,我可以这样做:

$total_cost1 = bcadd($value1, $value2);
$total_cost2 = bcadd($value3, $value4);
$total_cost3 = bcadd($value5, $value6);
$total_cost4 = bcadd($value7, $value8);

$total_cost = 
    bcadd(bcadd($total1_cost, $total2_cost), 
    bcadd($total3_cost, $total4_cost));
Run Code Online (Sandbox Code Playgroud)

但它使它变得如此不可读,并且很容易出错。请告诉我还有另一种方法可以解决这个问题......!?

php bcmath

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

使用clone()复制隐藏元素 - 更好的方法?

我设法$("#products-area").find(".mysets-area")通过检查元素的状态来复制隐藏的元素(),暂时显示它,然后在克隆后再次隐藏它.

但我可能认为实现这一目标会更好?

var stateVisible = $("#products-area").find(".mysets-area").css("display");
if (stateVisible == 'none') {
    $("#products-area").find(".mysets-area").show();
}

$("#user-dialog .open-mysets").html($("#products-area").find(".mysets-area").clone());                

if (stateVisible == 'none') {
    $("#products-area").find(".mysets-area").hide();
}
Run Code Online (Sandbox Code Playgroud)

jquery hidden clone elements

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

分页符和css - 如何跳过最后一页?

我有分页和css的问题:

我有这个html代码(由php生成)

<div class="form-table courses">
coursename and pupils...
</div>
<div class="form-table courses">
coursename and pupils...
</div>
<div class="form-table courses">
coursename and pupils...
</div>
Run Code Online (Sandbox Code Playgroud)

我的css是这样的:

.form-table.courses {page-break-after:always;}
Run Code Online (Sandbox Code Playgroud)

上面将生成4页,因为它甚至在上面的第三个div之后设置了分页符.是否有任何"简单"的方法来获得3页?

我在考虑css的last-child属性,但我理解在IE8及以下版本中不支持这种情况 - 而且这还不够好(它必须至少处理ie8 - 优选ie7).

当然我可以为最后一个div添加一个类,然后像这样修改css:

<div class="form-table courses">
coursename and pupils...
</div>
<div class="form-table courses">
coursename and pupils...
</div>
<div class="form-table courses lastpage">
coursename and pupils...
</div>
Run Code Online (Sandbox Code Playgroud)

并将此行添加到我的CSS:

.form-table.courses.lastpage {page-break-after:"";}
Run Code Online (Sandbox Code Playgroud)

我的解决方案是唯一具有某种跨浏览器兼容性的解决方案吗?或者我错过了一些我应该使用的css的属性/值?

html css page-break

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

是否(应该)本机js defaultValue和jQuery prop(defaultValue)之间有什么区别?

我对本机javascript defaultValue功能感到困惑.我已经明白必须设置html输入的值,并且该值是初始默认值.

当我在click-event中有这个时,我想将特定的输入(文本)元素恢复为其默认值.(取消按钮)

//Restore values
var name_person = $(this).find('.nameOfPerson');       

//Attempt 1
name_person.val(name_person.defaultValue);
alert('restored value=' + name_person.val()); //This alerts nothing

//Attempt 2
name_person.val(name_person.prop('defaultValue')); //This alerts the default value
alert('restored value=' + name_person.val());
Run Code Online (Sandbox Code Playgroud)

为什么prop('defaultValue')的原生defaultValue属性不起作用?那些基本上不一样吗?初始值在input元素中设置为value ="bla bla bla".

我得到了它(使用jQuery),但我只是想知道 - 我错过了什么?

javascript jquery default-value

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

do()也完成了对int的工作?

我在javascript(jquery)中有这段代码

function getTopLevelId(gender) {
            var catId = $.ajax({
            type: 'GET',
            url: '{url}'
            dataType: 'html'
        });

        return catId;   //Returns defered object    
    }

function getSelectedCategoryId() {
    return 7; //returns int based on value in an element
};


function mainFuncion(id) {
    if (parseInt(id) === 0) {
        catObj= getTopLevelId(gender);    //Returns defered object       
    }
    else {
        catId = getSelectedCategoryId(id);  //Returns int
        catObj = catId;
    }

    $.when(catObj).done(function(catId) {
            //Doing some stuff and want to use catId as a category id
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是在done()中做"做一些事情".它看起来就像done()被调用 …

javascript jquery

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

在Wordpress中为多个循环处理一个带有多维参数的WP_Query?

我想在下面优化我的代码.地点和舞蹈风格都是类别课程,但是由城镇位置1和城镇位置2(不是位置的是舞蹈风格,反之亦然)标识.

$locations = get_terms("categorycourses", array('include' => array(townLocation1, townLocation2)));                  
$dance_styles = get_terms("categorycourses", array('exclude' => array(townLocation1, townLocation2))); 

$content = '';

foreach ( $locations as $location ) {                                           
    $content .= . '<h1>'.$location->name.'</h1>';

    foreach ( $dance_styles as $dance_style ) {

        //Show courses that is associated with this dance-style
        //and in this location
        $loop = get_loop_courses($dance_style, $location->term_id); 

        if($loop->have_posts()) {   
        //show courses here (post with custom post type course)
        }

    } //end dance_styles
} //end locations


function get_loop_courses($categorycourse, $location_id) {
    $terms_slug = strtolower($categorycourse->slug);
    $terms_slug = str_replace(' …
Run Code Online (Sandbox Code Playgroud)

wordpress loops wp-query

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

在iframe中隐藏来自外部来源的内容?

我有som html看起来像这样......

HTML

<div class="container">
<div class="left-col">
</div>
<div class="right-col">
<iframe src="external-site" border="0" scroll="no">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

.container {overflow:hidden;}
.right-col iframe {margin-top:-100px;}
Run Code Online (Sandbox Code Playgroud)

我想要隐藏iframe中显示的外部网站的100个第一个顶部像素.它似乎适用于我测试的那些浏览器,但是在"智能电视"上测试它而不知道使用什么浏览器,有一个问题并不是所有的iframe都显示出来......但是我的问题是......

有没有其他方法可以实现我想做的事情?

html css iframe

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