カテゴリー: 未分類

  • サイト改装への道(12) 「Yii2のインストール上級編」

    昨日はBasicなテンプレートをインストールしたが、今日はAdvancedなテンプレートをインストールしてみる。
    こちらを参考に、昨日と違うコマンドを実行。

    $ composer create-project –prefer-dist yiisoft/yii2-app-advanced yii-advanced
    Installing yiisoft/yii2-app-advanced (2.0.4)
    – Installing yiisoft/yii2-app-advanced (2.0.4)
    Downloading: 100%
    Created project in yii
    Loading composer repositories with package information
    Installing dependencies (including require-dev)
    – Installing yiisoft/yii2-composer (2.0.3)
    Loading from cache
    – Installing ezyang/htmlpurifier (v4.6.0)
    Loading from cache
    – Installing cebe/markdown (1.1.0)
    Loading from cache
    – Installing bower-asset/jquery (2.1.4)
    Loading from cache
    – Installing bower-asset/jquery.inputmask (3.1.63)
    Loading from cache
    – Installing bower-asset/punycode (v1.3.2)
    Loading from cache
    – Installing bower-asset/yii2-pjax (v2.0.4)
    Loading from cache
    – Installing yiisoft/yii2 (2.0.4)
    Loading from cache
    – Installing swiftmailer/swiftmailer (v5.4.1)
    Downloading: 100%
    – Installing yiisoft/yii2-swiftmailer (2.0.4)
    Loading from cache
    – Installing yiisoft/yii2-codeception (2.0.4)
    Loading from cache
    – Installing bower-asset/bootstrap (v3.3.4)
    Loading from cache
    – Installing yiisoft/yii2-bootstrap (2.0.4)
    Loading from cache
    – Installing yiisoft/yii2-debug (2.0.4)
    Loading from cache
    – Installing bower-asset/typeahead.js (v0.10.5)
    Loading from cache
    – Installing phpspec/php-diff (v1.0.2)
    Loading from cache
    – Installing yiisoft/yii2-gii (2.0.4)
    Loading from cache
    – Installing fzaninotto/faker (v1.5.0)
    Loading from cache
    – Installing yiisoft/yii2-faker (2.0.3)
    Loading from cache
    fzaninotto/faker suggests installing ext-intl (*)
    Writing lock file
    Generating autoload files

    次にアプリケーションの初期化。因みに開発環境での初期化。

    $ php yii-advanced/init
    Yii Application Initialization Tool v1.0
    Which environment do you want the application to be initialized in?
      [0] Development
      [1] Production
      Your choice [0-1, or “q” to quit] 0
      Initialize the application under ‘Development’ environment? [yes|no] yes
      Start initialization …
       generate backend/config/main-local.php
       generate backend/config/params-local.php
       generate backend/web/index-test.php
       generate backend/web/index.php
       generate common/config/main-local.php
       generate common/config/params-local.php
       generate console/config/main-local.php
       generate console/config/params-local.php
       generate frontend/config/main-local.php
       generate frontend/config/params-local.php
       generate frontend/web/index-test.php
       generate frontend/web/index.php
       generate yii
       generate cookie validation key in backend/config/main-local.php
       generate cookie validation key in frontend/config/main-local.php
          chmod 0777 backend/runtime
          chmod 0777 backend/web/assets
          chmod 0777 frontend/runtime
          chmod 0777 frontend/web/assets
          chmod 0755 yii
          chmod 0755 tests/codeception/bin/yii
      … initialization completed.

    あとは、MySQLのデータベースを作成し、その内容でPHPファイルを更新。

    $ vi yii-advanced/common/config/main-local.php

    return [
        ‘components’ => [
            ‘db’ => [
                ‘class’ => ‘yiidbConnection’,
                ‘dsn’ => ‘mysql:host=127.0.0.1;port=8889;dbname=yii’,
                ‘username’ => ‘yii’,
                ‘password’ => ‘yii’,
                ‘charset’ => ‘utf8’,
            ],
            ‘mailer’ => [
                ‘class’ => ‘yiiswiftmailerMailer’,
                ‘viewPath’ => ‘@common/mail’,
                // send all mails to a file by default. You have to set
                // ‘useFileTransport’ to false and configure a transport
                // for the mailer to send real emails.
                ‘useFileTransport’ => true,
            ],
        ],

    ];

    今回は、MAMPを利用しているので、ポートが8889となっている。
    データベース名は、yii。
    ユーザもyii。

    あと、hostはlocalhostだと、migration時に次の様なエラーになるため、127.0.0.1に変更しておく。

    Exception ‘yiidbException’ with message ‘SQLSTATE[HY000] [2002] No such file or directory’

    in yii/vendor/yiisoft/yii2/db/Connection.php:534

    情報を元に、データベースの初期構成を行ってもらう。

    $ php yii-advanced/yii migrate
    Yii Migration Tool (based on Yii v2.0.4)
    Creating migration history table “migration”…Done.
    Total 1 new migration to be applied:
    m130524_201442_init
    Apply the above migration? (yes|no) [no]:yes
    *** applying m130524_201442_init
        > create table {{%user}} … done (time: 0.019s)
    *** applied m130524_201442_init (time: 0.025s)

    Migrated up successfully.

    これで次のURLでフロントエンド、バックエンドのページが表示される。

    http://localhost:8888/yii-advanced/frontend/web/index.php
    http://localhost:8888/yii-advanced/backend/web/index.php

    落とし穴いっぱい。疲れるよ。

  • サイト改装への道(11) 「Yii2のインストール」

    サイト改装への道(11) 「Yii2のインストール」

    まずは、「はじめに:インストール」を参考に、次のページからダウンロード。
    http://www.yiiframework.com/
    と思ったら、Composerでインストールする手も。
    最近、使う機会が多いが、Mac OS Xでのインストール方法は、

    $ curl -sS https://getcomposer.org/installer | php
    #!/usr/bin/env php
    All settings correct for using Composer
    Downloading…
    Composer successfully installed to: /Users/username/composer.phar
    Use it: php composer.phar

    以上!

    あれ?インストール先が/Users/username/になってる。

    移動しとこう。

    $ mv composer.phar /usr/local/bin/composer

    これによって、

    $ php composer.phar 〜

    と、コマンドを実行するところ、

    $ composer 〜

    で、実行できるようになる。

    本題に戻って、Yiiをインストール、と思ったら、先にプラグインのインストールが必要。

    $ composer global require “fxp/composer-asset-plugin:1.0.0”
    Changed current directory to /Users/username/.composer
    ./composer.json has been created
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    – Installing fxp/composer-asset-plugin (v1.0.0)
    Downloading: 100%
    Writing lock file
    Generating autoload files
    で、やっとYiiをインストール。今度こそ。

    基本的なテンプレートか、アドバンスドなテンプレートか選びますが、今回は基本的な方を選んで、

    $ composer create-project yiisoft/yii2-app-basic basic 2.0.4
    Installing yiisoft/yii2-app-basic (2.0.4)  – Installing yiisoft/yii2-app-basic (2.0.4)    Downloading: 100%         
    Created project in basicLoading composer repositories with package informationInstalling dependencies (including require-dev)Reading bower.json of bower-asset/jquery.inputmask (3.1.56)Could not fetch https://api.github.com/repos/RobinHerbots/jquery.inputmask/contents/bower.json?ref=xxxxxxxxxxxxxxxxx, please create a GitHub OAuth token to go over the API rate limitHead to https://github.com/settings/tokens/new?scopes=repo&description=yyyyyyyyyyyyto retrieve a token. It will be stored in “/Users/username/.composer/auth.json” for future use by Composer.Token (hidden): 

    と、なんだか途中で止まってしまいました。

    調べてみると、Githubへのアクセスは、認証なしの場合、同じIPアドレスから1時間で60回までとなっているようで、それを超えたようです。
    因みに、次のコマンドで、あと何回アクセスできるかが分かります。

    $ curl -i https://api.github.com/users/whatever
    HTTP/1.1 403 Forbidden
    Server: GitHub.com
    Date: Sat, 06 Jun 2015 11:58:23 GMT
    Content-Type: application/json; charset=utf-8
    Content-Length: 257
    Status: 403 Forbidden
    X-RateLimit-Limit: 60
    X-RateLimit-Remaining: 0
    X-RateLimit-Reset: 1433594536

    60回中、残り0。はい。もうダメです。

    因みに、リセットされるのは、1433594536っていう時間。
    Macだと、次のコマンドで何時何分かが分かります。

    $ date -r 1433594536
    2015年 6月 6日 土曜日 21時42分16秒 JST

    では、Githubのアカウントを持っているであろう事を祈りつつ、次のページに行って、
    https://github.com/settings/tokens

    [Generate new token]ボタンをクリックして、トークンを入手してください。

    因みに、次のコマンドで、残りが確認できます。

    $ curl -i -H “Authorization: token 12345678901234567890123456789012” https://api.github.com/users/whatever
    HTTP/1.1 200 OK
    Server: GitHub.com
    Date: Sat, 06 Jun 2015 12:35:33 GMT
    Content-Type: application/json; charset=utf-8
    Content-Length: 1096
    Status: 200 OK
    X-RateLimit-Limit: 5000
    X-RateLimit-Remaining: 4843
    X-RateLimit-Reset: 1433596872

    5000回だって。


    ま、取得したトークンを入力して続ければ、インストールされる。

    $ composer create-project yiisoft/yii2-app-basic basic 2.0.4
    Installing yiisoft/yii2-app-basic (2.0.4)
      – Installing yiisoft/yii2-app-basic (2.0.4)
        Loading from cache
    Created project in basic
    Loading composer repositories with package information
    Installing dependencies (including require-dev)
      – Installing yiisoft/yii2-composer (2.0.3)            
        Loading from cache
      – Installing ezyang/htmlpurifier (v4.6.0)
        Downloading: 100%      
      – Installing cebe/markdown (1.1.0)
        Downloading: 100%      
      – Installing bower-asset/jquery (2.1.4)
        Downloading: 100%      
      – Installing bower-asset/jquery.inputmask (3.1.63)
        Downloading: 100%      
      – Installing bower-asset/punycode (v1.3.2)
        Downloading: 100%      
      – Installing bower-asset/yii2-pjax (v2.0.4)
        Downloading: 100%      
      – Installing yiisoft/yii2 (2.0.4)
        Downloading: 100%      
      – Installing swiftmailer/swiftmailer (v5.4.0)
        Downloading: 100%      
      – Installing yiisoft/yii2-swiftmailer (2.0.4)
        Downloading: 100%      
      – Installing yiisoft/yii2-codeception (2.0.4)
        Downloading: 100%      
      – Installing bower-asset/bootstrap (v3.3.4)
        Downloading: 100%      
      – Installing yiisoft/yii2-bootstrap (2.0.4)
        Downloading: 100%      
      – Installing yiisoft/yii2-debug (2.0.4)
        Downloading: 100%      
      – Installing bower-asset/typeahead.js (v0.10.5)
        Downloading: 100%      
      – Installing phpspec/php-diff (v1.0.2)
        Downloading: 100%      
      – Installing yiisoft/yii2-gii (2.0.4)
        Downloading: 100%      
      – Installing fzaninotto/faker (v1.5.0)
        Downloading: 100%      
      – Installing yiisoft/yii2-faker (2.0.3)
        Downloading: 100%      
    fzaninotto/faker suggests installing ext-intl (*)
    Writing lock file
    Generating autoload files
    chmod(‘runtime’, 0777)…done.
    chmod(‘web/assets’, 0777)…done.
    chmod(‘yii’, 0755)…done.
    で?

  • 無線LANルーター物色

    色々調子悪くなる。

    無線LANルーターを探す。

    I-O DATA WN-AC1167GR
    最大867Mbps

    エレコム WRC-733GHBK, WRC-733GHBK-I
    最大433Mbps、PS4専用?
    最後の”-I”の有無の違いは、「IKARUSが1年間、U-NEXTが30日間無料使用可能でこどもネットタイマー含め家族で使えるルーターです。」の有無。

    エレコム GM-WRC733GHBK
    最大433Mbps、PS4専用?

    “GM”の違いは?

    もう眠くて分からん。

  • サイト改装への道(10) 「PHPフレームワークを選定」

    このシリーズも書き始めてから5年、昔調べたFrameworkも状況が変化してきた。
    PHP Frameworksというサイトにて、一覧をざっくり見て、全てに対応しているものを探る。

    MVC: Indicates whether the framework comes with inbuilt support for a Model-View-Controller setup.
    Multiple DB’s: Indicates whether the framework supports multiple databases without having to change anything.
    ORM: Indicates whether the framework supports an object-record mapper, usually an implementation of ActiveRecord.
    DB Objects: Indicates whether the framework includes other database objects, like a TableGateWay.
    Templates: Indicates whether the framework has an inbuilt template engine.
    Caching: Indicates whether the framework includes a caching object or some way other way of caching.
    Validation: Indicates whether the framework has an inbuilt validation or filtering component.
    Ajax: Indicates whether the framework comes with inbuilt support for Ajax.
    Auth Module: Indicates whether the framework has an inbuilt module for handling user authentication.
    Modules: Indicates whether the framework has other modules, like an RSS feed parser, PDF module or anything else (useful).
    EDP: Event Driven Programming.

    残ったのは2つだけ。 2つともPHP4には対応していないが、今の環境では関係ないので無視した。
    Yii
    Prado

    さて、いじってみるか。

  • 「成功した人が絶対に言わない7つのこと」を訳してみた

    1. 「それは私の仕事じゃないんで!」
    “That’s not in my job description.”
    2. 「できっこないっすよ〜」
    “It can’t be done.”

    3. 「私のせいじゃないですよ〜」
    “It’s not my fault.”
    4. 「すぐできますよ〜」
    “This will just take a minute.”
    5. 「1人でできるもん!」
    “I don’t need any help.”
    6. 「それはずるいですよ〜」
    “It’s not fair.”
    7. 「いつもそうやってますから!」
    “This is the way it’s always been done.”
    なぜか?
    答えはこちら