GithubHelp home page GithubHelp logo

o0h / cakephp-with-me Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 2.83 MB

CakePHPを使っていて感じた「こうしたいな」「こうできるな」をまとめていきます

Home Page: https://cake.nichiyoubi.land/

HTML 100.00%

cakephp-with-me's People

Contributors

o0h avatar

Watchers

 avatar  avatar

cakephp-with-me's Issues

collectionを任意の順番で並び替える

MySQLでいう ORDER BY FIELD(field, idx1, idx2, idx3) みたいなやつ。

$order = [2, 1, 3];
$data = collection([
    ['id' => 1, 'name' => 'John'],
    ['id' => 2, 'name' => 'Alice'],
    ['id' => 3, 'name' => 'Yui'],
]);
$orderMap = array_flip($order);
$data = $data->sortBy(
    function ($datum) use ($orderMap) {
        return $orderMap[$datum->id];
    },
    SORT_ASC
    )->compile(false);

CakePHP2に関するtipsも触れていいかも・・?

  • (やや不本意ながら)「これまでより古いバージョン」も業務上触る事が増えてきたので
  • 他方で、CakePHP3については「何か自分で手を動かす」ものを自身で作っていかないと機会創出ができていない
    • (もちろんcake4も扱いたい・・!
  • ということで、自ずと「1番触る機会や思いを馳せる場面が多い」のは、今今だとCake2 😇

もともとが「調べてみる・新しく得た知識をまとめる」だけでなく「知っている・体感がある知見について最言語化する」というのも目的なので、「CakePHP3」に縛らなくても良い(そもそも3以降のver.は扱うものとして考えている)はずで、じゃあcake2やるか〜〜〜という感じがある

(Componentの)initializeとconstructをどう使い分けるか

RequestHandlerComponentが分かりやすかったと思う

https://github.com/cakephp/cakephp/blob/585453bdd0e6b890bdad8019a02170d0283afa60/src/Controller/Component/RequestHandlerComponent.php#L100
※masterではinitializeが廃止予定に入っているので、設計**が汲みやすい時点でのスナップショット

  • construct: configをいじる〜とかだけにしておく
  • initialise: もっとゴニョる。メンバーへの作用とか

同一テーブルに関する複数のFixtureを扱う

  • クラス名(basename)を別々にしてFixtureを用意する
  • $fixtures に、利用可能性のある全てのFixtureClassを列挙する
  • $autoFixture をfalseにする
  • 必要なものをすべてテストケース中からloadFixtures() でロードする

Database/ORMの違いを意識する

Cake2のときは「Model」でまとまっていた部分だと思う(確か

特に Database\QueryとORM\Queryがあるのとか顕著で、1回コード読まないと感じにくい部分かな?と思うのでまとめてみよう

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.