小编Flo*_*ild的帖子

Symfony2无效表单没有错误

我有一个Symfony2生成的CRUD表单的问题.(使用MongoDB文档,但我不认为这是相关的)

在我的控制器的createAction()方法中,当我调试表单结果时:

$form->isValid() // returns false

$form->getErrors() // returns en empty array(0) {}
Run Code Online (Sandbox Code Playgroud)

所以,我没有form_errors(form)在我的树枝模板上使用任何东西(这似乎是正常的,因为$form->getErrors()空的返回)

并且书面价值不会以表格形式替换......

有没有人有想法?

forms validation symfony

61
推荐指数
5
解决办法
7万
查看次数

根据室外温度设置背景颜色

Heyoh SO,

我有一个温度小部件来实现我正在进行的项目.没有什么是特别困难的,我有一个免费的API来检索我需要的数据等.

但是,和我一起工作的可爱设计师会有一个颜色特征我开始时没有好主意......

他会根据当前的天气温度定义背景颜色.

温度颜色模式

我的意思是如果温度很冷,比如-20,背景颜色应该是蓝色/紫色/任何冷色; 当它像25一样温暖时,它应该有一个像橙色/红色的热背景颜色.

我想我可以很容易地使用一系列"温度步骤",但我更喜欢使用可以根据温度定义颜色的功能.我知道这很奇怪,我不知道是否有算法通过它的温度颜色来定义颜色...这篇文章很有用http://en.wikipedia.org/wiki/Color_temperature但很复杂,如果有人有任何想法,即使是一个开始,我都很感兴趣!

我看到了这个话题: 用C#将温度显示为一种颜色?

但我不是在使用C#而我不想这样做,所以如果JavaScript中有解决方案,那就完美了.如果存在服务器端需求,我最终可以使用PHP或NodeJS.

编辑 - 答案:

最后,由于图形需要,我没有选择使用真彩色渐变阵列.但我仍然需要根据温度混合最近步骤的颜色!我写了一个小的JS库来做到这一点,你很快就可以在GitHub上找到,我会在这里发布链接.

你可以在这里找到它:

该项目的演示网站

或者是github项目

javascript colors temperature

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

自定义grunt-modernizr与非核心检测

由于一天,我发现了自耕农,我用它为我所有前端项目.

它包括grunt-modernizr - 至少我认为 - 下载库并在我调用构建任务时动态编译它

grunt build
Run Code Online (Sandbox Code Playgroud)

但我有一个小问题:默认情况下,它不包括我们在网上可以看到的"非核心检测":modernizr custom builder

这是我的grunt-modernizr任务配置(Gruntfile.js文件的一部分):

modernizr: {
    devFile: '<%= yeoman.app %>/components/modernizr/modernizr.js',
    outputFile: '<%= yeoman.dist %>/components/modernizr/modernizr.js',
    extra: {
        'shiv' : true,
        'printshiv' : false,
        'load' : true,
        'mq' : false,
        'cssclasses' : true
    },
    extensibility: {
        'addtest': true,
        'prefixed': false,
        'teststyles': false,
        'testprops': false,
        'testallprops': false,
        'hasevents': false,
        'prefixes': false,
        'domprefixes': false
    },
    files: [
        '<%= yeoman.dist %>/scripts/{,*/}*.js',
        '<%= yeoman.dist %>/styles/{,*/}*.css',
        '!<%= yeoman.dist %>/scripts/vendor/*'
    ],
    uglify: true
}
Run Code Online (Sandbox Code Playgroud)

实际上我想使用Modernizr.getusermedia,但作为非核心功能,它没有定义...因为grunt-modernizr配置似乎不允许非核心检测到包含.关于这一点的任何想法?

编辑:现代化任务不再起作用; …

javascript modernizr gruntjs getusermedia

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

具有禁用选项的Symfony Choice类型

有没有办法让Symfony <select>根据给定choices选项的真实性呈现具有禁用选项的表单类型?

我看到这个线程(感谢DonCallisto)关于禁用选择扩展选项; 但是我不希望有更多的选择.我想保留一个select残疾人的元素options.

$builder->add('list', 'choice', array(
    'choices' => array(
        array(
            'value' => 1,
            'label' => '1',
            'disabled' => false
        ),
        array(
            'value' => 2,
            'label' => '2',
            'disabled' => false
        ),
        array(
            'value' => 3,
            'label' => '3',
            'disabled' => true
        )
    ),
    // Instead of
    // 'choices' => array(
    //     1 => 'Option 1',
    //     2 => 'Option 2',
    //     3 => 'Option 3'
    // )
);

# Which …
Run Code Online (Sandbox Code Playgroud)

forms choice custom-field-type symfony

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

context.drawImage()不适用于新的Image()实例(chrome)

我试图找出为什么在画布中绘制之前经典的图像预加载方式是在chrome上触发"类型错误".

我们来看看情况:

我尝试以3种不同的方式预加载图像:

  1. 创建一个新的Image()实例
  2. 创建一个图像元素
  3. 创建一个jQuery图像对象

或者如果你喜欢一些代码:

var canvas1 = document.getElementById('canvas-1'),
    context1 = canvas1.getContext('2d'),
    image1 = new Image(),
    canvas2 = document.getElementById('canvas-2'),
    context2 = canvas2.getContext('2d'),
    image2 = document.createElement('img'),
    $canvas3 = $('#canvas-3'),
    context3 = $canvas3.get(0).getContext('2d'),
    $image3 = $('<img>'),
    loadImage = function (image, context, debugIndice) {
        debugIndice = debugIndice || -1;
        image.onload = function () {
            try {
                context.drawImage(this, 0, 0, 100, 100);
            }
            catch (e) {
                console.log('error for debugIndice', debugIndice, e, this);
            }
        }
        image.src = "http://upload.wikimedia.org/wikipedia/commons/8/87/Google_Chrome_icon_%282011%29.png";
    };

loadImage(image1, context1, 1);
loadImage(image2, …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome canvas image preloading

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

Laravel Carbon本地化不起作用(从数字获取本地化的月份名称)

使用Laravel 5.3,

在我的方法中我使用

setlocale(LC_TIME, 'hr-HR');
dd(Carbon::now()->formatLocalized('%A'));
Run Code Online (Sandbox Code Playgroud)

但我得到了Sunday而不是CroatianWordForSunday.

我尝试使用Carbon::setLocale('hr'),而不是setlocale(),但我仍然得到Sunday.

在我的config/app.php文件中,我已设置'locale' => 'hr'.

需要注意的是,diffForHumans()如果我使用Carbon的方法已成功翻译Carbon::setLocale('hr').

最后,我要做的就是将8号转换为8月份,但是克罗地亚语.我总是可以手动将1月改为Siječanj等等,但如果可以使用一些PHP或Carbon的方法来保持我的代码简洁,那将会很好.

php datetime locale php-carbon laravel-5.3

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

Xcode构建错误clang失败

我的iPhone应用程序中缺少某些东西.

我没有成功修复这个错误,接缝对我来说是一个火星错误...我甚至在经过多次搜索之后根本不理解......

ProcessPCH /Users/xyz/Library/Developer/Xcode/DerivedData/IntraMuros-cqmesmesegqjxofftymiymllpzow/Build/Intermediates/PrecompiledHeaders/IntraMuros-Prefix-etlohrlrqzwcjicedfazzdvoaqbq/IntraMuros-Prefix.pch.pth IntraMuros/IntraMuros-Prefix.pch normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd "/Users/xyz/iOS - Applications/intramuros-ios/Application"
setenv LANG en_US.US-ASCII
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c-header -arch i386 -fmessage-length=0 -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fexceptions -fasm-blocks -Wprotocol -Wdeprecated-declarations -mmacosx-version-min=10.6 -g -Wno-conversion -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -iquote /Users/xyz/Library/Developer/Xcode/DerivedData/IntraMuros-cqmesmesegqjxofftymiymllpzow/Build/Intermediates/IntraMuros.build/Debug-iphonesimulator/IntraMuros.build/IntraMuros-generated-files.hmap -I/Users/xyz/Library/Developer/Xcode/DerivedData/IntraMuros-cqmesmesegqjxofftymiymllpzow/Build/Intermediates/IntraMuros.build/Debug-iphonesimulator/IntraMuros.build/IntraMuros-own-target-headers.hmap -I/Users/xyz/Library/Developer/Xcode/DerivedData/IntraMuros-cqmesmesegqjxofftymiymllpzow/Build/Intermediates/IntraMuros.build/Debug-iphonesimulator/IntraMuros.build/IntraMuros-all-target-headers.hmap -iquote /Users/xyz/Library/Developer/Xcode/DerivedData/IntraMuros-cqmesmesegqjxofftymiymllpzow/Build/Intermediates/IntraMuros.build/Debug-iphonesimulator/IntraMuros.build/IntraMuros-project-headers.hmap -I/Users/xyz/Library/Developer/Xcode/DerivedData/IntraMuros-cqmesmesegqjxofftymiymllpzow/Build/Products/Debug-iphonesimulator/include -I/Users/xyz/iOS …
Run Code Online (Sandbox Code Playgroud)

objective-c clang xcode4.3 mapbox

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

react-router和cordova无法正常工作

React-router似乎无法处理通过本地文件协议运行的任何内容.

它将file://后面的第三个斜杠解释为路径.

因此,如果您创建一个应用程序并尝试从file:/// C:/myapp.html运行它

它认为您正在尝试访问路由/C:/myapp.html并抛出错误说

"警告:位置"/C:/myapp.html"与任何路线都不匹配.

当通过文件协议提供应用程序时,有没有办法让react-router工作?

截至目前,路由器根本无法使用cordova/phonegap,因为它们将所有内容都作为本地文件提供.

file-uri cordova react-router

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

使用Mongoid配置CarrierWave - GridFS

我遇到了麻烦,尝试使用CarrierWave在Rails 3中开发的文件上传Rest API,使用MongoDB数据库.

我想要做的是使用MongoDB系统GridFS存储一些文件(不仅是图像,而且是每种文件格式).我阅读了许多建议我使用CarrierWave gem的文档.

但是当我尝试配置它时出错.

我的开发环境:Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.8'

# MongoDB
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
gem 'carrierwave', :git => "git://github.com/jnicklas/carrierwave.git"
# gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'mini_magick', :git => 'git://github.com/probablycorey/mini_magick.git'

gem 'bson_ext'
gem 'json'
Run Code Online (Sandbox Code Playgroud)

application.rb:

require File.expand_path('../boot', __FILE__)

# ActiveRecord will not be use with MongoDB
# require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
require "mongoid/railtie"
require "carrierwave"
# require "carrierwave/mongoid"
Run Code Online (Sandbox Code Playgroud)

我用mongoid.yml(config/mongoid.yml)文件定义数据库:

development:
  sessions:
    default:
      database: lf_rest_api_development
      hosts:
        - localhost:27017 …
Run Code Online (Sandbox Code Playgroud)

mongodb gridfs mongoid carrierwave ruby-on-rails-3.2

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