小编Con*_*ing的帖子

从同一PHP类中的另一个方法调用方法

我正在尝试使用类中另一个方法中的方法.我没有PHP5 OOP的经验,我四处寻找答案,但找不到任何答案.我正在尝试在sendRequest()中使用getClientInfo(),它位于同一个类中.

class DomainHandler {

    public static function getClientInfo($db, $client_id)
    {
        //Do stuff
    }

    public static function sendRequest($details)
    {

        require_once('MySQL.class.php');
        $db = new MySQL;

        getClientInfo($db, $client);
    }
}
Run Code Online (Sandbox Code Playgroud)

它告诉我:

致命错误:调用未定义的函数getClientInfo()

我也试过了

parent::getClientInfo($db, $client); 
Run Code Online (Sandbox Code Playgroud)

$this->getClientInfo($db, $client);
Run Code Online (Sandbox Code Playgroud)

无济于事.

有任何想法吗?

php oop methods class

36
推荐指数
2
解决办法
6万
查看次数

使用每日cron作业在Rails中使用Ice Cube创建事件的正确方法

我想在Rails中使用Ice Cube gem创建重复事件 - 我的问题是,我如何正确地,或者更有效地使用这些重复规则来触发实际事件?

这方面的一个例子是定期发票.

假设我每周一次设置一个Ice Cube重复集,并使用to_yaml将其保存到定期发票行.我现在在数据库中有一行带有序列化重复规则.我可以想象使用它的唯一方法是遍历数据库中的每一行,反序列化保存的重复规则并检查它是否需要今天运行schedule.occurs_on?(Date.new) - 然后将其放入每天运行的cronjob:

items = RecurringItem.find(:all)
items.each do |item|
    schedule = Schedule.from_yaml(item.schedule_yaml)
    if schedule.occurs_on?(Date.new)
        #if today is a recurrence, do stuff!
    end
end
Run Code Online (Sandbox Code Playgroud)

这看起来非常低效 - 但我可能完全错了.有没有更好的方法来使用冰立方?

recursion cron ruby-on-rails

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

如何在Heroku Postgres数据库上启用contrib模块

我正在尝试在Heroku上的新Postgres 9共享数据库中使用contrib模块.更具体地说,是pg_trgmfuzzystrmatch模块.在文档中

此外,还提供许多免费扩展,例如fuzzystrmatch,pg_trgm和unaccent.

我似乎无法找到关于如何在共享的Heroku数据库上实际启用这些模块的任何文档.见下面的答案.

注意:

我尝试通过连接数据库来添加它们

heroku pg:psql HEROKU_POSTGRESQL_BROWN
Run Code Online (Sandbox Code Playgroud)

并运行

create extension pg_trgm
create extension fuzzystrmatch
Run Code Online (Sandbox Code Playgroud)

但在尝试使用它之后

SELECT levenshtein('tests', 'test');
Run Code Online (Sandbox Code Playgroud)

它仍然说

ERROR:  function levenshtein(unknown, unknown) does not existLINE 1: SELECT levenshtein('tests', 'test');
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

谁知道为什么会这样?

postgresql ruby-on-rails heroku

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

使用libsass和Rails资产管道

我正在尝试让libsass使用Rails 4资产管道.到目前为止,我已经将Github中的ruby-libsass Gem 克隆到我的应用程序的Vendor文件夹中.我将followig添加到我的gemfile中:

gem 'sassc', path: 'vendor/ruby-libsass/'
Run Code Online (Sandbox Code Playgroud)

然后我按照文档添加了libsass的子模块.在libsass文件夹中,我必须在sass2scss库中克隆才能进行编译.我用make install-shared它创建了它/usr/local/lib/libsass.so.在此之后,运行rake assets:precompile会出现以下错误:

rake aborted!
LoadError: Could not open library 'sass': dlopen(sass, 5): image not found.
Could not open library 'libsass.dylib': dlopen(libsass.dylib, 5): image not found
Run Code Online (Sandbox Code Playgroud)

所以我把libsass.dylib这个符号链接到了/usr/local/lib/libsass.dylib.之后,我收到以下错误:

NameError: uninitialized constant SassC::Lib::Context::SassOptions

我尝试在/ruby-libsass/lib/sassc/lib/context.rb调用SassOptions时注释掉这一行,这似乎使它工作并编译资产.第20行注释掉的代码context.rb:

layout :source_string, :pointer,
  :output_string, :string,
  # :options, SassOptions,
  :error_status, :int,
  :error_message, :string,
  :c_functions, :pointer,
  :included_files, :pointer,
  :num_included_files, :int`
Run Code Online (Sandbox Code Playgroud)

现在,我遇到的问题是我看不到速度差异.无论是否将libsass添加到我的Gemfile,它都会在7秒左右的时间内编译我的资产.由于初始编译给出了一个与libsass.dylib文件无关的错误,我认为它实际上是使用sassc而不是sass,但它看起来并非如此.

我有什么想法可以错过吗?我没有使用C的经验,所以我甚至不确定我是否正确编译了所有内容,等等.

ruby ruby-on-rails sass libsass

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

CKEditor和Poltergeist/PhantomJS - [CKEDITOR.resourceManager.load]在"http://cdn.ckeditor.com"找不到资源名称"default"

[CKEDITOR.resourceManager.load] Resource name "default" was not found at "http://cdn.ckeditor.com/4.4.7/full/styles.js?t=F0RD".

我在Poltergeist中运行集成测试时间歇性地遇到此错误.在研究这个问题的时候,我看到一些有这个问题的老线程与实际丢失的资产有关,但是从CDN加载了库,所以我无法控制资产.

有任何想法吗?

ckeditor phantomjs poltergeist

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

如何在Code Igniter中向Model发送完整的POST

在Code Igniter中向模型发送完整帖子的最佳方法是什么?我知道的方法如下:

将表单元素命名为数组,例如.

<input type="text" name="contact[name]">
<input type="text" name="contact[surname]">
Run Code Online (Sandbox Code Playgroud)

然后使用:

$this->Model_name->add_contact($this->input->post('contact'));
Run Code Online (Sandbox Code Playgroud)

另一种方法是将每个元素添加到数组中,然后将其发送到模型中:

<input type="text" name="name">
<input type="text" name="surname">
Run Code Online (Sandbox Code Playgroud)

$contact_array = array('name' => $this->input->post('name'),
                       'surname' => $this->input->post('surname'));
$this->Model_name->add_contact($contact_array);
Run Code Online (Sandbox Code Playgroud)

其中哪一个是最好的做法,是有没有办法直接发送POST整体的模型(或整个形式也许?)

php post model codeigniter

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

为什么RSpec/Capybara没有显示错误发生的位置

我正在使用带有webkit的Capybara进行测试,但出于某种原因,当测试失败时,它会显示错误,但不会显示代码中实际发生的错误.

Failures:

  1) online shopping -  sign up
     Failure/Error: page.should have_content 'Payment added successfully'
       expected there to be content "Payment added successfully" in "Internal Server Error undefined method `client_id' for #<InvoicePayment:0x007fbd5b834008> WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at 127.0.0.1:60324"
     # ./spec/requests/online_shopping_spec.rb:140:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

当使用save_and_open_page它时,只显示错误,没有关于它发生位置的信息:

内部服务器错误

#NETrick/1.3.1的未定义方法`client_id'(Ruby/1.9.3/2012-04-20),版本127.0.0.1:60324

我期待看到的是错误发生的行号和功能:

app/controllers/invoices_controller.rb:30:在'show'中

我似乎无法在Google上找到与此相关的任何内容.我可能使用了错误的命名法.有谁知道如何解决这个问题?

rspec ruby-on-rails capybara capybara-webkit

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

在wordpress中使用wp_get_attachment_image()的正确方法

我正在寻找使用wp_get_attachment_image()的正确方法.

以下代码:

<?php
    $args = array(
        'type' => 'attachment',
        'category_name' => 'portfolio'
        );
    $attachments = get_posts($args);
    print_r($attachments);
?>
Run Code Online (Sandbox Code Playgroud)

生成以下结果:

Array
(
    [0] => stdClass Object
        (
            [ID] => 54
            [post_author] => 1
            [post_date] => 2010-06-22 00:32:46
            [post_date_gmt] => 2010-06-22 00:32:46
            [post_content] => <a href="http://localhost/wordpress/wp-content/uploads/2010/06/Capture.jpg"><img class="alignnone size-medium wp-image-55" title="Capture" src="http://localhost/wordpress/wp-content/uploads/2010/06/Capture-300x114.jpg" alt="" width="300" height="114" /></a> 
            [post_title] => Our Own Site
            [post_excerpt] => 
            [post_status] => publish
            [comment_status] => open
            [ping_status] => open
            [post_password] => 
            [post_name] => our-own-site
            [to_ping] => 
            [pinged] => 
            [post_modified] => …
Run Code Online (Sandbox Code Playgroud)

php wordpress wordpress-theming

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

jQuery悬停回调函数问题

我试图让图像在点击时保持不透明,并在悬停时使用淡入/淡出功能.单击它时,它将删除一个类并向该元素添加一个"选定"类.问题是,除去原始类之外,回调仍然执行,好像该类仍在元素中.因此,如果单击它,它会将不透明度更改为1并删除.gallery_item类,但仍会在悬停时淡出该元素.我知道代码可以改进,但它仅用于演示目的.

悬停代码:

$(".gallery_item img").hover(
    function () {
        $(this).fadeTo('50', 1);
    },
    function () {
        $(this).fadeTo('50', 0.6);
    }
);
Run Code Online (Sandbox Code Playgroud)

单击代码/使元素不透明度为1:

$(".gallery_item img").click(function() {
    $('.gallery_item').removeClass('gallery_item_selected');
    $(this).parent().addClass('gallery_item_selected').removeClass('gallery_item');
    $(this).css("opacity", "1");
});
Run Code Online (Sandbox Code Playgroud)

我做错了什么/它是一个更好的方法来完成这个?

jquery class hover

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

使用 Jest、Vue Test Utils 和 Moxios 测试 VueJS 时,`moxios.wait` 从不执行

我正在尝试为 VueJS 组件编写我的第一个单元测试,该组件在呈现时从 API 端点获取一些数据:

我的 VueJS 组件:

import axios from 'axios';

export default {
  props: {
          userIndexUrl: {
            required: true
          }
        },
  data() {
    userList: [],
    tableIsLoading: true
  },
  created() {
    const url = this.userIndexUrl;
    axios.get(url)
    .then(response => {
      this.userList = response.data.data;
      this.tableIsLoading = false;
    })
  },
}
Run Code Online (Sandbox Code Playgroud)

和我的测试:

import { mount } from 'vue-test-utils'
import moxios from 'moxios'
import UsersAddRemove from 'users_add_remove.vue'

describe('UsersAddRemove', () => {
  const PROPS_DATA = {
      userIndexUrl: '/users.json'
  }

  beforeEach(() => {
    moxios.install();
    moxios.stubRequest('/users1.json', …
Run Code Online (Sandbox Code Playgroud)

vue.js moxios

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