投稿者: admin Page 13 of 47

Windows(InternetExploler/Edge)でインターネットのSambaへのリンク(UNCリンク)を開く設定。

Windows(InternetExploler/Edge)でインターネットのSambaへのリンク(UNCリンク)を開く設定。

2017.12月現在はできました。

いろいろパスを変えてもできなかったのですが、セキュリティー設定を変更するとできました。
インターネットセキュリティーのプロパティーを開いて、[セキュリティー]タブの“信頼済サイト”に該当サイトを追加します。(サイトがhttpsでない場合はhttps必須のチェックを外す)
→InternetExploler/Edgeともこれで開けるようになります。

リンクはfile::///から初めるかたち。

<a href="file:///\exampele.compathtofile_or_dir">リンク文字列</a>

ちなみにMacは、そのままsmb://~で行けました。(iPad/iPhone/Androidなどはどうなるかは未検証

<a href="smb://exampele.com/path/to/file_or_dir">リンク文字列</a>

限定した業務システムなどでは使えそうな感じです。

Laravelで日付の検索、YYYYMMDDの形式の場合。前方後方真ん中、年月日組み合わせ検索。

Laravelで日付の検索、YYYYMMDDの形式の場合。前方後方真ん中、年月日組み合わせ検索。

をつくってみた。

public static function set_date_search($query,$date,$targetKey){
        $y = ($date['year'])?'1':'0';
        $m = ($date['month'])?'1':'0';
        $d = ($date['day'])?'1':'0';
        $ymd = ''.$y.$m.$d;
        switch($ymd){
            case '001':
                return $query->where($targetKey,'like','______'.$date['day']);
            case '011':
                return $query->where($targetKey,'like','____'.$date['month'].$date['day']);
            case '100':
                return $query->where($targetKey,'like',$date['year'].'____');
            case '110':
                return $query->where($targetKey,'like',$date['year'].$date['month'].'__');
            case '010':
                return $query->where($targetKey,'like','____'.$date['month'].'__');
            case '101':
                return $query->where($targetKey,'like',$date['year'].'__'.$date['day']);
            case '111':
                return $query->where($targetKey,'=',dateArr2DbString($date));
            default:
                return $query;
        }
    }

PHPでいろいろな種類の改行コードを簡単に配列に格納する。のは”R” がよさそう。

PHPでいろいろな種類の改行コードを簡単に配列に格納する。のは“R” がよさそう。

参考
http://php.net/manual/ja/regexp.reference.escape.php

そのままですが。

$lines = preg_split('/R/',$text);

$textはテキストエリアなどに入力された文字を想定。
win/macどちらからでも

Laravelで任意の場所(親コントローラー)などで強制リダイレクトする方法。

Laravelで任意の場所(親コントローラー)などで強制リダイレクトする方法。

ふつうのコントローラーだと。アクションで return して上げればリダイレクトできる。

    function restore($request){
        ・
        ・
        return Redirect::route("item.index")->with('message', '登録しました。'); 
    }

ただ、親のコントローラーや別のメソッドからだとできない場合は以下の様にする。

    function hoge(){
        Redirect::route('item.index')->withErrors(['redirect'=>'エラー発生'])->throwResponse();
    }

Redirect(ファザード)の実態は。IlluminateRoutingRedirector で、
route()->withErrors()を実行した戻り値は。IlluminateHttpRedirectResponse
その RedirectResponseクラスのthrowResponse();を実行している流れ。

Laravel5.5で、一覧ページのPaginationにソートを追加する。(sort,orderby)

Laravel5.5で、一覧ページのPaginationにソートを追加する。(sort,orderby)

こちらを使わせてもらいました。

kyslik/column-sortable
https://github.com/Kyslik/column-sortable

まずはcomposerでインストール。

$ composer require kyslik/column-sortable

config/app.phpの providersに追加


    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        IlluminateAuthAuthServiceProvider::class,
        IlluminateBroadcastingBroadcastServiceProvider::class,
        IlluminateBusBusServiceProvider::class,
            ・
            ・
            ・
            ・
        /*
         * paginate sortable ※こちら
         */
        KyslikColumnSortableColumnSortableServiceProvider::class,

    ],

モデルに追記。

<?php

namespace App;

use IlluminateDatabaseEloquentModel;
use SymfonyComponentHttpFoundationRequest;

use KyslikColumnSortableSortable; //※ここと。

class User extends Model
{    
    use Sortable;  // ※ココ

ビューは以下の様に

<th>@sortablelink('email','メールアドレス')</th>

Laravelで簡単にExcelからのCSVを読み込んで処理したい。

Laravelで簡単にExcelからのCSVを読み込んで処理したい。

Goodby, CSV
https://github.com/goodby/csv#requirements

composer.json のrequireに“goodby/csv”を追加。

"require": {
    "goodby/csv": "*"
}

して、composerをアップデート

$ composer update
$ composer dump-autoload

モデル、ライブラリをuseして使う。

app/ItemCsv.php
<?php
namespace App;

use IlluminateDatabaseEloquentModel;

use GoodbyCSVImportStandardLexer;
use GoodbyCSVImportStandardInterpreter;
use GoodbyCSVImportStandardLexerConfig;

class ItemCsv extends Model
{
    
    protected $table = 'items'; 
    
    public static function import($path){
    
        $config = new LexerConfig();
        $config->setToCharset("UTF-8");
        $config->setFromCharset("sjis-win");
        $interpreter = new Interpreter();
        $tmp = array();
        $interpreter->addObserver(function(array $row) use (&$tmp) {
            $tmp[] = $row;
        });
        $lexer = new Lexer($config);
        $lexer->parse($path, $interpreter);
        dd($tmp);
    }
    
}

あとは、何処かしらから。

ItemCsv::import($path_to_csv_file);

LaravelのRouterでドットシンタックスで指定する’name’が登録されない。

LaravelのRouterでドットシンタックスで指定する’name’が登録されない。

解決した方法。

//routes/web.php
Route::post('item/import/confirm',['as'=>'item.import.confirm','uses'=>'ItemController@importConfirm']);

‘as’ で指定する。実行先は ‘uses’

ルート一覧確認方法

$ php artisan route:list

脱jQuery $.proxy(fn,this)の代わりに fn.bind(this)

脱jQuery $.proxy(fn,this)の代わりに fn.bind(this)

jQueryのときは、Class内部のメソッド呼び出し時に$.proxy()をつかってましたが、bind()が楽。

class Foo {

    constructor(){
        $('#btn1').on('click',this.onClick1);
        $('#btn2').on('click',$.proxy(this.onClick2,this);
        $('#btn3').on('click',this.onClick3.bind(this));
    }   
    onClick1(e){
        console.log(this); //thisのスコープが #btn1のElementになる。
    }
    onClick2(e){
        console.log(this); //thisのスコープがclass Fooになる。
    }
    onClick3(e){
        console.log(this); //thisのスコープがclass Fooになる。
    }

}


Laravelのモデル(Eloquent)にバーチャル(仮想/カスタム)フィールドを追加する($appends)

Laravelのモデル(Eloquent)にバーチャル(仮想/カスタム)フィールドを追加する($appends)

CakePHPのバーチャルフィールドの様な仮想のフィールドの設定方法。

class User extends Model
{
    protected $appends = ['name'];
    public function getNameAttribute()
    {
        return $this->lastname. ' ' .$this->firstname;
    }
    ・
    ・
    ・
  1. $appends にフィールド名を追加。
  2. getXxxAttributeというメソッドを追加。

あとはビューで。以下の様に参照するだけ。

$user->name;

Veu.jsの “v-for” 繰り返し部分での双方向データバインディング(data-binding , v-model)

Veu.jsの “v-for” 繰り返し部分での双方向データバインディング(data-binding , v-model)

が、うまく行かなく、始めたところでなかなか情報も見つけにくかったのでメモがてら。

<div id="items">
    <table>
             <tr v-for="(cut,index) in items">
                <td>アイテム{{ index+1 }}</td>
                <td>
                        <input class="u-wd200 u-mr10" name="mst_cut" v-model="items[index]"/>
                </td>
            </tr>
    </table>
</div>

Page 13 of 47

Powered by WordPress & Theme by Anders Norén