小编d3b*_*g3r的帖子

Laravel 5 Carbon格式的日期时间

我有一个返回以下日期时间的数组:

$item['created_at'] => "2015-10-28 19:18:44"
Run Code Online (Sandbox Code Playgroud)

如何M d Y使用Carbon 更改Laravel格式的日期?

目前它返回错误

$suborder['payment_date'] = $item['created_at']->format('M d Y');
Run Code Online (Sandbox Code Playgroud)

php laravel php-carbon laravel-5

30
推荐指数
8
解决办法
13万
查看次数

从ngThumb指令上传AngularJS文件(使用angular-file-upload)

我正在使用Angular-File-Upload将文件上传到服务器.一切正常,文件可以保存在DB中.

问题是,如何在编辑模式下加载我保存的图像?

这是canvas上传pic时创建的指令

'use strict';

myApp

    .directive('ngThumb', ['$window', function($window) {
        var helper = {
            support: !!($window.FileReader && $window.CanvasRenderingContext2D),
            isFile: function(item) {
                return angular.isObject(item) && item instanceof $window.File;
            },
            isImage: function(file) {
                var type =  '|' + file.type.slice(file.type.lastIndexOf('/') + 1) + '|';
                return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
            }
        };

        return {
            restrict: 'A',
            template: '<canvas/>',
            link: function(scope, element, attributes) {
                if (!helper.support) return;

                var params = scope.$eval(attributes.ngThumb);

                if (!helper.isFile(params.file)) return;
                if (!helper.isImage(params.file)) return;

                var canvas = element.find('canvas');
                var …
Run Code Online (Sandbox Code Playgroud)

php laravel angularjs angularjs-directive angular-file-upload

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

AngularJS ui-select下拉默认值

我使用角度ui-select下拉.如何为下拉值设置默认值?

<h3>Selectize theme</h3>
  <p>Selected: {{country.selected}}</p>
  <ui-select ng-model="country.selected" theme="selectize" ng-disabled="disabled" style="width: 300px;">
    <ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="country in countries | filter: $select.search">
      <span ng-bind-html="country.name | highlight: $select.search"></span>
      <small ng-bind-html="country.code | highlight: $select.search"></small>
    </ui-select-choices>
  </ui-select>
Run Code Online (Sandbox Code Playgroud)

该片段来自plnkr.co.目前下拉菜单只播放默认Select or search a country in the list...但我需要从控制器传递一个值.让我们说$scope.default = {"name":"Decard"}

谢谢!!

编辑

这个问题与类似,但涉及json返回格式的数据.

javascript angularjs ui-select2

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

基于SHA的git pull

我想知道如何从基于SHA的回购拉?

git pull origin master
Run Code Online (Sandbox Code Playgroud)

一旦我们完成,上面的代码将拉大师git add remote.

git

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

AngularJS多重解析

这是我ui-router对特定路线的配置

state('app.merchant', {
                url: '/start/merchant',
                views: {
                    'mainView': {
                        templateUrl: "partials/start_merchant.html"
                    }
                },
                css: ['assets/vendor/bootstrap/dist/css/bootstrap.css','assets/css/styles.css','assets/css/plugins.css'],
                title: 'Buttons',

                resolve: {
                    userRequired: userRequired,
                }

                resolve: loadSequence('flow','angularFileUpload','MerchantWizardCtrl')

            })
Run Code Online (Sandbox Code Playgroud)

问题是,即使页面不符合userRequired要求,页面也会显示.这是以下功能userRequired:

function userRequired($q, $location, $auth,Account) {
      var deferred = $q.defer();
      if ($auth.isAuthenticated()) {

          Account.getUserStatus()
              .then(function(response){
                if(response.data == true){
                    deferred.resolve();
                }
                  else{
                    deferred.reject();
                }
              })
              .catch(function(response){
                  console.log("Error has occur, Please contact adminstrator");
              });
      } else {
          deferred.resolve();
      }
      return deferred.promise;
    }
Run Code Online (Sandbox Code Playgroud)

怎么解决这个?谢谢!!

编辑

loadsequence:

function loadSequence() {
        var _args = …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angular-ui-router

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

Zend多国重定向

目前我在默认位置有一个Zend应用程序 www.example.com/{controller}/{action}

但是当用户从特定国家/地区访问时,如何检测其IP地址并将其重定向到此基于countryCode的网址 www.example.com/uk/{controller}/{action}

为了检测用户访问的国家,我写了一个帮手:

require_once '../library/Ipinfo/ip2locationlite.class.php';

class Application_View_Helper_GetLocation extends Zend_View_Helper_Abstract
{
    public function getLocation()
    {

        $ipLite = new ip2location_lite;
        $ipLite->setKey('APIKEY');

        //Get errors and locations
        $locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
        $errors = $ipLite->getError();

        $country = strtolower($locations['countryName']);

        return "$country";
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码将返回国家/地区名称.如果用户正在从法国访问,我该如何重写网址以便网址成为example.com/france/{controller}/{action}

php zend-framework

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

根据另一个表的值有条件地更新一个表

嗨,我有2个表:user_badgesbadges表,以下是user_badges表数据:

id | user_id | badge_id | points_earned | badges_awarded |
 1    2324        0             5               0
Run Code Online (Sandbox Code Playgroud)

如果用户满足最低要求点,即badges表中的5 ,SQL将更新上述内容:

id | user_id | badge_id | points_earned | badges_awarded |
 1    2324        1             5               1
Run Code Online (Sandbox Code Playgroud)

如果将来为同一用户注册了新点,user_table徽章将添加一个新行,如下所示:

 id | user_id | badge_id | points_earned | badges_awarded |
  1    2324        1             5               1
  2    2324        0             7               0
Run Code Online (Sandbox Code Playgroud)

上述问题已经解决


这是badges表:

badge_id | badge_name | required_points
   1           new          5
   2           adv          10
Run Code Online (Sandbox Code Playgroud)

以下是我的需要 …

php mysql

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

Ruby on Rails,使用具有相同名称的枚举的问题

以下是我视图中的一些下拉菜单:

<div class="col-xs-3">
    <%= f.select(:require_booking, get_advance_booking.collect {|p| [ p[:require_booking], p[:require_booking] ] }, {include_blank: false} , :class => 'form-control') %>
</div>
Run Code Online (Sandbox Code Playgroud)

<div class="col-xs-3">
    <%= f.select(:instant_booking, get_instant_booking.collect {|p| [ p[:instant_booking], p[:instant_booking] ] }, {include_blank: false} , :class => 'form-control') %>
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的 application_helper.rb

  def get_advance_booking
    ret = [{:require_booking => 'No'},{:require_booking => 'Yes'}]
  end

 def get_instant_booking
    ret = [{:instant_booking => 'No'},{:instant_booking => 'Yes'}]
  end
Run Code Online (Sandbox Code Playgroud)

但现在问题是,在我的模型中product.rb,我无法使用相同的名称设置枚举:

class Product < ActiveRecord::Base
    enum require_booking: {
        No: 0,
        Yes: 1
    }
    enum instant_booking: { …
Run Code Online (Sandbox Code Playgroud)

ruby enums ruby-on-rails

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

Mysql组post_id按最大计数状态

嗨,我有一个mysql查询,它将返回post_id最大状态计数,它当前显示的结果

POST_ID

    3
Run Code Online (Sandbox Code Playgroud)

Mysql表:

(`post_id`, `user_id`, `status`, `date_created`)
(2, 2, 'funny', 20121022120627)
(2, 3, 'lame', 20121023120627)
(3, 1, 'useful', 20121023120627)
(3, 3, 'lame', 20121023120627)
(3, 4, 'useful', 20121023120627)
(4, 4, 'useful', 20121024120627)
Run Code Online (Sandbox Code Playgroud)

但我需要的结果是,在desc order.if 2结果具有相同数字时显示从max到min的计数,那么最高结果将基于最新的date_created类似这样

POST_ID

     3
     2
     4
Run Code Online (Sandbox Code Playgroud)

我目前的疑问是

SELECT post_id
FROM tableName
GROUP BY post_ID
HAVING COUNT(*) = 
(
    SELECT MAX(x.counts)
    FROM
    (
        SELECT post_id, COUNT(*) counts
        FROM tableName
        GROUP BY post_id
    ) x
)
Run Code Online (Sandbox Code Playgroud)

该示例可以在SQLFiddle SQLFiddle找到

mysql sql database

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

AngularJS ui 模态传递数据

用户可以在此处ui-select选择一个选项:

<ui-select ng-model="state.selected" ng-change="openModal(state.selected,orders.order_id)" ng-if="orders.state == 'Paid'" theme="selectize" ng-disabled="disabled" style="width: 300px;"> .....
Run Code Online (Sandbox Code Playgroud)

每当有变化时,它就会从引导程序触发模式

$scope.openModal = function(name,oid){
    $scope.modalInstance = $modal.open({
        templateUrl: 'reservationModal.html',
        scope:$scope,
        name: function(){
            return name;
        }
    });
}

$scope.cancel = function(){
    $scope.modalInstance.dismiss();
}

$scope.confirmChg = function(){
    console.log('ok...');
}
Run Code Online (Sandbox Code Playgroud)

模板如下:

<script type="text/ng-template" id="reservationModal.html">
    <div class="modal-header">
        <h3 class="modal-title">Confirmation</h3>
        <!--<button class="btn btn-warning" ng-click="close()">X</button>-->
    </div>
    <div class="modal-body">
        Confirm to change status to {{name}} ?

    </div>
    <div class="modal-footer">
        <button class="btn btn-danger" type="button" ng-click="confirmChg(status_oid,status)">Yes</button>
        <button class="btn btn-warning" type="button" ng-click="cancel()" data-dismiss="modal">No</button>
    </div>
</script>
Run Code Online (Sandbox Code Playgroud)

问题是, …

javascript angularjs angular-ui

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