ラベル laravel4 の投稿を表示しています。 すべての投稿を表示
ラベル laravel4 の投稿を表示しています。 すべての投稿を表示

2015年6月14日日曜日

Laravel5と郵便番号用ajaxのajaxzip3.js

Laravel5でちょっとしたWebシステムを開発することになった。ちなみに、2014年10月ごろにはLaravel4でWebシステムを開発した。Laravel4とLaravel5はフォルダの配置とデフォルトの設定が随分変わったので、最初かなり戸惑った。
 それはさて置き、 ajaxzip3.jsと郵便番号の話です。フォームに郵便番号を入れると住所欄に住所が入るWEBページがよくあります。自分で作らなければいけないと思い、日本郵便のページから郵便番号のファイルをダウンロードして、簡単なプログラムを書いて、郵便番号のデータをMySQLに取り込んだ。

<2015/6/14追加>
Google Codeがサービス廃止になり、Githubに移行したそうです。私のページも動かなくなったので驚きましたが、理由が分かれば、安心。
Github移行を機にこれまでhttp、httpsで分かれていたURLを一本化したそうです。
今後は、https://ajaxzip3.github.io/ajaxzip3.js に成ります。(http://でも使えるみたいですが、基本はhttps://です。)
今までは、http://ajaxzip3.googlecode.com/svn/trunk/ajaxzip3/ajaxzip3.js だった。下記の部分もこの部分は読み替えてください。書き換えてください。

その後Javascriptの見本が見たくて、Googleで検索したら、ajaxzip3 と言う、驚異的なページを見つけてしまった。  ajaxzip3.jsを使えば、もう自分で郵便番号を用意する必要はない。ホームページに書くコードも至極簡単だ。ヘッダーの中で下記:
http://ajaxzip3.googlecode.com/svn/trunk/ajaxzip3/ajaxzip3.jsを読み込み。
本文のフォームの中に下記のように書く(私が書いたコードで、余分に、class="eisu"とtype="tel"で英数字化、placeholder="453"でグレーの初期値表示、onKeyPress="return submitStop(event)で改行キーでの送信の拒否、を入れている)。データベースを3桁4桁にしているので、入力用フォームも3桁4桁に分けている。
<td>
<input class="eisu" maxlength="3" placeholder="453" onKeyPress="return submitStop(event);" name="zip21" type="tel" value="">
</td><td>
<input class="eisu" maxlength="4" placeholder="0042" onKeyUp="AjaxZip3.zip2addr(zip21,zip22,addr21,addr21);" onKeyPress="return submitStop(event);" name="zip22" type="tel" value="">
</td>
ajaxzip3の動作見本ページはここです。

ajaxzip3のURLを見ると、https://code.google.com/p/ajaxzip3/と、google.comのドメインになっている。ajaxzip3.jsの設置場所も、googlecode.comになっている。Google Project Hostingというページで、オープンソースをGoogleが応援しているようだ。Googleがこのようなことを行っているのははじめて知った。(上に追加で記したように、Google Codeはサービス廃止だそうです。)


2014年11月18日火曜日

Laravel4 Migrations Tips

As we read programming books or homepages, we sometimes encounter the confusion because of the different explanations from authers to authers.

Laravel's Migrations is in that case. Let's me explain the best use of migrate:make command.

First, here are three lines for migrate:make command. You will see which is the best way to write seeing the results.

Laravel4 Formal Documentation

1. $ php artisan migrate:make create_users

2. $ php artisan migrate:make create_users --table=users
2-2. $ php artisan migrate:make create_users --table="users" //Double quotations are not required. This line shoud be like upper one.

Sorry, I made a mistake. 3-2 is wrong. 3 is a true line I intended. Originally, I wrote this blog in august.
3. $ php artisan migrate:make create_users --create=users
3-2. $ php artisan migrate:make create_users --create --table=users

The results for each command are like below.

The result for the first command line.
------------------------------
<?php
use Illuminate\Database\Migrations\Migration;
class CreateUsers extends Migration {
/**
* Run the migrations.
*
* @return void
*/
 public function up()
 {
  //
 }
/**
* Reverse the migrations.
*
* @return void
*/
 public function down()
 {
  //
 }
}
-------------------------------


The result for the second command line.
-------------------------------
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsers extends Migration {
/**
* Run the migrations.
*
* @return void
*/
 public function up()
 {
  Schema::table('users', function(Blueprint $table) {
  });
 }
/**
* Run the migrations.
*
* @return void
*/
 public function down()
 {
  Schema::table('users', function(Blueprint $table) {
  });
 }
}
-----------------------------


The result for the last command line.
-----------------------------
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsers extends Migration {
/**
* Run the migrations.
*
* @return void
*/
 public function up()
 {
  Schema::create('users', function(Blueprint $table) {
   $table->increments('id');
   $table->timestamps();
  });
 }
/**
* Reverse the migrations.
*
* @return void
*/
 public function down()
 {
  Schema::drop('users');
 }
}
------------------------------


The last line is the best for us. The migrate:make command make more job for us with the last. It's result makes us saving the coding time with less errors.

2014年9月4日木曜日

Laravel4のディレクトリ設定

ホームページを作成するとき、普段、ディレクトリは直接Web用のルートディレクトリに置かないようにしている。
例えば、/var/www/htmlがApacheのルートだとすると、/var/www/web1に、様々なモジュールやファイルを置く。そのweb1ディレクトリを、conf.dディレクトリの中のweb1.confで、http://www.sample.com/web1などに成るようにAliasを設定して、Webアクセスするようにしている。

ところが、Laravel4のインストールディレクトリを、/var/www/laravel4にし、conf.dディレクトリの中で、http://www.sample.com/laravel4に成るようにAliasを設定しても、エラーが発生してWebアクセスができない。

何かを間違えているのかと、目を凝らして一字づつチェックしたが、記述に問題はない。半日悩んだが、解決策は簡単と言われれば簡単なことだ。

ln -s /var/www/laravel4/public/ /var/www/html/laravel4 とリンクを貼った。これで無事にWebアクセスができた。
あとは、なぜ、conf.dディレクトリの中での設定ではエラーを起こすかを突き止めておきたい。