もくもく会を主催した感想
kikedaです。 先日(1/10)にもくもく会を主催しました。
もくもく会に参加することはしばしばありましたが、主催する側になるのは初めてで、 開催してみて気になることや、反省点がありましたので、ずらずらと書いていきたいと思います。
(ちなみにだれかを批判するつもりはありません。)
集合時間がやや遅れる。
これは、参加するとき僕もよく遅刻していました。 主催する場合、会場を開く時間と自己紹介の時間をずらしておくといいかもしれませんね。
だれがなにをしているのかわからない。
途中で参加される方で、質問できるならしたかったけれども、だれがなにを知っているのかわからなかったとのこと。これは上記の自己紹介の時間をずらすことや、テキストによる共有や、チャットを準備することで解決しようかなと考えています。
質問できると助かる。
これは、自分のもくもく会の方向性で、経験者枠と未経験者(学生、プログラミング歴が浅い)などの枠で分けて、質問に答えられる方と分けることも考えていました。ただ、言語のしばりがなく、集まっている方の技術レベルが明確にならない以上(なおかつ、そういういった対応を極力したくない場合、自分がもくもくするために来ているため)、絶対数を確保するのは「もくもく会」という形だと実現できないかなと思っています。そもそもできている会については良いと思います。
僕は、もくもく会を1人で作業するよりか複数人で作業するほうが捗るという趣旨に賛同して開催しています。その個人個人がもくもく作業できるのが理想かなぁと思っていて、それでも時間を割いて、参加者の中で質問を受け付けていても構わない方で、扱える言語を調べて、サポートするのが自分の主催するもくもく会でできることだと思いました。
また開催して欲しいという声について
定期的に開くというのが、義務みたいになってしまうと感じていまして、自分のやりたいときに、開こうと思っています。
今後のもくもく会について
不特定多数の人たちが集まって、その中の人達で、質問したり、回答したりしていくことが自然かなぁと思っていまして、できる限りそれをコミュニティの運営方法でカバーできないかなと考えています。
良い方法や、知識があれば今後、もくもく会に適用していきたいですし、もくもく会の方向性も固めていきたいと思っていますので、参加者の方々、また開催する際には、楽しんでもくもくもらえれば嬉しいかぎりです。
ではでは。
PHPのempty関数
備忘録ですね。自分のローカルの環境では、エラーが発生しなかったのですが、他の方の環境ではエラーになり、対応しました。
環境
- codeigniter 2.2
- PHP 5.5系
empty関数
引数が空であるかを評価して、true/falseを返却する関数です。 ただし、issetなどの変数を評価する関数と引数により返す値が変わりますので、そのあたりの細かい知識は前提として持っておいたほうが良いです。
エラーになった際のコード。サンプルです。
if (empty(set_value('domestic', 'hoge')) { echo 'true'; }
修正コード
$value = set_value('domestic', 'hoge'); if (empty($value)) { echo 'true'; }
以上で、動作します。
MySql 外部参照制約
こんにちは。kikedaです。
スキーマを作成して、外部参照制約をつける機会があったので、備忘録です。Googleで検索することはあるんですが、やはり自分のブログを検索して、作業する機会が多いので「他人」より「自分」に向けての、記事を多くなりそうです。
MySqlの外部参照制約
MySqlで外部キーを持つテーブルで、関係を記述することにより、外部キーの元となるマスタテーブルの値もしくは、テーブルそのもの削除と更新を防止することができます。挙動については、指定するパラメータにより細かく変えることができますが、今回の目的は、マスタテーブルのレコードを、外部キーが参照しているレコードが存在する間は、削除と更新を防止させます。 親のレコードが消されて、つながりが示されなくなるのを防ぎます。
外部参照制約をつける。
> alter table table_name add constraint 制約名 foreign key (外部キーの列名) references テーブル名(列名) on delete cascade on update cascade;
MySql Workbenchを利用することで、データベースやテーブルを定義をして、Sqlを作成することができますので、そちらから利用することもオススメです。
以上です。
codeigniterのヘルパー
こんにちは。RubyとRailsが触りたいですが、日々を過ごしているkikedaです。
「あんな技術のないやつらに・。」とか空耳を聞くくらいなので、記事書いたら休みたいです。
今日は、codeigniterを触っていて、ヘルパーを覚える機会があったので、そちらを記述していきます。
viewで使われるヘルパー
form_input
まずは、input type="text"をcodeigniterのヘルパーで記述します。
<?php echo form_input('name', set_value('name', $data ? $data->id : ''), 'class="wrapper"' ) ?>
set_valueは、formのaction先でvalidation_ruleをセットして、validation->runをを走らせた際に、codeigniterが保持してくれる値です。validation->runで値の検証がエラーになった際に、検証した値を名前を指定して保存することができます。もちろんリクエスト毎ですよ。
form_checkbox
<?php echo form_checkbox('name', '1', $value ? $value == '1' : '', 'class="chk"') ?>
ひとまず、2つだけご紹介でした。 ちなみに、公式のサイトに各種ヘルパーの利用サンプルと解説が載っていますので、詳細はそちらを参考にしてください。
以上。
codeigniter2.2 エラー対応(Only variable references should be returned by reference)
こんにちは。kikedaです。
codeigniter 2.2で開発したプロジェクトにブラウザからアクセスした際に、エラーが発生したので対応しました。備忘録です。
エラーメッセージ
Severity: Notice Message: Only variable references should be returned by reference Filename: core/Common.php Line Number: 257
system/core/Common.php
# 変更前 return $_config[0] =& $config; # 変更後 $_config[0] =& $config; return $_config[0];
phpのバージョンに依存するのか。MAMPから起動してもらった際にも確認しましたが、 CentOSで確認した際にも同様に起こりましたね。
環境
参考URL
codeigniter2.2の環境設定
こんにちは。rubyが好きですが、業務でPHPを書くことになり、まずは業務をこなせることを見せようと思っているkikeda1104です。このタイトルで書くのもあれですが、Rubyのコミニティに貢献できるようになりたいですねぇ。
で、codeigniter2.2というフレームワークをプロジェクトで利用していますが、フレームワークそのものにバグがあったり、日本語のドキュメントの更新がとまっていたり、仕様がややおかしいなと思えるフレームワークです。(あんまり好ましく思っていないです。)
後ほど説明しますが、学習コストが低いことが利点としてあげられていますが、学習コストが0になるわけではなく、それなりにはかかるので、プロジェクトの立ち上げ時にはフレームワークの知識の習得や慣れも見積もりに入れるべきだと思います。(参加プロジェクトでも、当初から伝えていますし、遅れていても、自分を責めるつもりはありません。(何)
とはいえ、プロジェクトに参加される方に迷惑をかけたくはないので、できる限り時間を投資していきたい。自社サービスの際にはチームになりますしね。まぁ、余談です。
それで本題です。
デザイナーの方に(HTML+CSSをコーディングしていただける方)に環境設定のお手伝いをする機会があったので、 備忘録として書いておきます。
codeigniterとは
PHPで書かれているwebアプリケーションフレームワークです。特徴としてあげているのが、学習コストが低い。つまり、構成やDSLが単純であることが売りのようです。2011年で日本語のサイトの更新が止まっていますが、当時世界的にもシェアが高かったようです。
公式ホームページ
- 日本語公式ページ
- 日本語のユーザドキュメント
CodeIgniterへようこそ : CodeIgniter ユーザガイド 日本語版
日本語のドキュメントは古いので、海外の公式を参考にするようにしましょう。
環境構築
環境構築は簡単で、codeigniterをダウンロードすることで利用できます。
http://www.codeigniter.com/downloadからダウンロードして解凍します。
$ wget https://github.com/bcit-ci/CodeIgniter/archive/2.2-stable.zip $ unzip 2.2-stable.zip
ディレクトリ構成は以下のようですね。
$ CodeIgniter-2.2-stable . ├── application │ ├── cache │ │ └── index.html │ ├── config │ │ ├── autoload.php │ │ ├── config.php │ │ ├── constants.php │ │ ├── database.php │ │ ├── doctypes.php │ │ ├── foreign_chars.php │ │ ├── hooks.php │ │ ├── index.html │ │ ├── migration.php │ │ ├── mimes.php │ │ ├── profiler.php │ │ ├── routes.php │ │ ├── smileys.php │ │ └── user_agents.php │ ├── controllers │ │ ├── index.html │ │ └── welcome.php │ ├── core │ │ └── index.html │ ├── errors │ │ ├── error_404.php │ │ ├── error_db.php │ │ ├── error_general.php │ │ ├── error_php.php │ │ └── index.html │ ├── helpers │ │ └── index.html │ ├── hooks │ │ └── index.html │ ├── index.html │ ├── language │ │ ├── english │ │ │ └── index.html │ │ └── index.html │ ├── libraries │ │ └── index.html │ ├── logs │ │ └── index.html │ ├── models │ │ └── index.html │ ├── third_party │ │ └── index.html │ └── views │ ├── index.html │ └── welcome_message.php ├── index.php ├── license.txt ├── system │ ├── core │ │ ├── Benchmark.php │ │ ├── CodeIgniter.php │ │ ├── Common.php │ │ ├── Config.php │ │ ├── Controller.php │ │ ├── Exceptions.php │ │ ├── Hooks.php │ │ ├── index.html │ │ ├── Input.php │ │ ├── Lang.php │ │ ├── Loader.php │ │ ├── Model.php │ │ ├── Output.php │ │ ├── Router.php │ │ ├── Security.php │ │ ├── URI.php │ │ └── Utf8.php │ ├── database │ │ ├── DB_active_rec.php │ │ ├── DB_cache.php │ │ ├── DB_driver.php │ │ ├── DB_forge.php │ │ ├── DB.php │ │ ├── DB_result.php │ │ ├── DB_utility.php │ │ ├── drivers │ │ │ ├── cubrid │ │ │ │ ├── cubrid_driver.php │ │ │ │ ├── cubrid_forge.php │ │ │ │ ├── cubrid_result.php │ │ │ │ ├── cubrid_utility.php │ │ │ │ └── index.html │ │ │ ├── index.html │ │ │ ├── mssql │ │ │ │ ├── index.html │ │ │ │ ├── mssql_driver.php │ │ │ │ ├── mssql_forge.php │ │ │ │ ├── mssql_result.php │ │ │ │ └── mssql_utility.php │ │ │ ├── mysql │ │ │ │ ├── index.html │ │ │ │ ├── mysql_driver.php │ │ │ │ ├── mysql_forge.php │ │ │ │ ├── mysql_result.php │ │ │ │ └── mysql_utility.php │ │ │ ├── mysqli │ │ │ │ ├── index.html │ │ │ │ ├── mysqli_driver.php │ │ │ │ ├── mysqli_forge.php │ │ │ │ ├── mysqli_result.php │ │ │ │ └── mysqli_utility.php │ │ │ ├── oci8 │ │ │ │ ├── index.html │ │ │ │ ├── oci8_driver.php │ │ │ │ ├── oci8_forge.php │ │ │ │ ├── oci8_result.php │ │ │ │ └── oci8_utility.php │ │ │ ├── odbc │ │ │ │ ├── index.html │ │ │ │ ├── odbc_driver.php │ │ │ │ ├── odbc_forge.php │ │ │ │ ├── odbc_result.php │ │ │ │ └── odbc_utility.php │ │ │ ├── pdo │ │ │ │ ├── index.html │ │ │ │ ├── pdo_driver.php │ │ │ │ ├── pdo_forge.php │ │ │ │ ├── pdo_result.php │ │ │ │ └── pdo_utility.php │ │ │ ├── postgre │ │ │ │ ├── index.html │ │ │ │ ├── postgre_driver.php │ │ │ │ ├── postgre_forge.php │ │ │ │ ├── postgre_result.php │ │ │ │ └── postgre_utility.php │ │ │ ├── sqlite │ │ │ │ ├── index.html │ │ │ │ ├── sqlite_driver.php │ │ │ │ ├── sqlite_forge.php │ │ │ │ ├── sqlite_result.php │ │ │ │ └── sqlite_utility.php │ │ │ └── sqlsrv │ │ │ ├── index.html │ │ │ ├── sqlsrv_driver.php │ │ │ ├── sqlsrv_forge.php │ │ │ ├── sqlsrv_result.php │ │ │ └── sqlsrv_utility.php │ │ └── index.html │ ├── fonts │ │ ├── index.html │ │ └── texb.ttf │ ├── helpers │ │ ├── array_helper.php │ │ ├── captcha_helper.php │ │ ├── cookie_helper.php │ │ ├── date_helper.php │ │ ├── directory_helper.php │ │ ├── download_helper.php │ │ ├── email_helper.php │ │ ├── file_helper.php │ │ ├── form_helper.php │ │ ├── html_helper.php │ │ ├── index.html │ │ ├── inflector_helper.php │ │ ├── language_helper.php │ │ ├── number_helper.php │ │ ├── path_helper.php │ │ ├── security_helper.php │ │ ├── smiley_helper.php │ │ ├── string_helper.php │ │ ├── text_helper.php │ │ ├── typography_helper.php │ │ ├── url_helper.php │ │ └── xml_helper.php │ ├── index.html │ ├── language │ │ ├── english │ │ │ ├── calendar_lang.php │ │ │ ├── date_lang.php │ │ │ ├── db_lang.php │ │ │ ├── email_lang.php │ │ │ ├── form_validation_lang.php │ │ │ ├── ftp_lang.php │ │ │ ├── imglib_lang.php │ │ │ ├── index.html │ │ │ ├── migration_lang.php │ │ │ ├── number_lang.php │ │ │ ├── profiler_lang.php │ │ │ ├── unit_test_lang.php │ │ │ └── upload_lang.php │ │ └── index.html │ └── libraries │ ├── Cache │ │ ├── Cache.php │ │ ├── drivers │ │ │ ├── Cache_apc.php │ │ │ ├── Cache_dummy.php │ │ │ ├── Cache_file.php │ │ │ ├── Cache_memcached.php │ │ │ └── index.html │ │ └── index.html │ ├── Calendar.php │ ├── Cart.php │ ├── Driver.php │ ├── Email.php │ ├── Encrypt.php │ ├── Form_validation.php │ ├── Ftp.php │ ├── Image_lib.php │ ├── index.html │ ├── javascript │ │ ├── index.html │ │ └── Jquery.php │ ├── Javascript.php │ ├── Log.php │ ├── Migration.php │ ├── Pagination.php │ ├── Parser.php │ ├── Profiler.php │ ├── Session.php │ ├── Sha1.php │ ├── Table.php │ ├── Trackback.php │ ├── Typography.php │ ├── Unit_test.php │ ├── Upload.php │ ├── User_agent.php │ ├── Xmlrpc.php │ ├── Xmlrpcs.php │ └── Zip.php └── user_guide ├── changelog.html ├── database │ ├── active_record.html │ ├── caching.html │ ├── call_function.html │ ├── configuration.html │ ├── connecting.html │ ├── examples.html │ ├── fields.html │ ├── forge.html │ ├── helpers.html │ ├── index.html │ ├── queries.html │ ├── results.html │ ├── table_data.html │ ├── transactions.html │ └── utilities.html ├── doc_style │ ├── index.html │ └── template.html ├── general │ ├── alternative_php.html │ ├── ancillary_classes.html │ ├── autoloader.html │ ├── caching.html │ ├── cli.html │ ├── common_functions.html │ ├── controllers.html │ ├── core_classes.html │ ├── creating_drivers.html │ ├── creating_libraries.html │ ├── credits.html │ ├── drivers.html │ ├── environments.html │ ├── errors.html │ ├── helpers.html │ ├── hooks.html │ ├── libraries.html │ ├── managing_apps.html │ ├── models.html │ ├── profiling.html │ ├── quick_reference.html │ ├── requirements.html │ ├── reserved_names.html │ ├── routing.html │ ├── security.html │ ├── styleguide.html │ ├── urls.html │ └── views.html ├── helpers │ ├── array_helper.html │ ├── captcha_helper.html │ ├── cookie_helper.html │ ├── date_helper.html │ ├── directory_helper.html │ ├── download_helper.html │ ├── email_helper.html │ ├── file_helper.html │ ├── form_helper.html │ ├── html_helper.html │ ├── inflector_helper.html │ ├── language_helper.html │ ├── number_helper.html │ ├── path_helper.html │ ├── security_helper.html │ ├── smiley_helper.html │ ├── string_helper.html │ ├── text_helper.html │ ├── typography_helper.html │ ├── url_helper.html │ └── xml_helper.html ├── images │ ├── appflowchart.gif │ ├── arrow.gif │ ├── ci_logo_flame.jpg │ ├── ci_logo.jpg │ ├── ci_quick_ref.png │ ├── codeigniter_1.7.1_helper_reference.pdf │ ├── codeigniter_1.7.1_helper_reference.png │ ├── codeigniter_1.7.1_library_reference.pdf │ ├── codeigniter_1.7.1_library_reference.png │ ├── file.gif │ ├── folder.gif │ ├── nav_bg_darker.jpg │ ├── nav_separator_darker.jpg │ ├── nav_toggle_darker.jpg │ ├── reactor-bullet.png │ ├── smile.gif │ └── transparent.gif ├── index.html ├── installation │ ├── downloads.html │ ├── index.html │ ├── troubleshooting.html │ ├── upgrade_120.html │ ├── upgrade_130.html │ ├── upgrade_131.html │ ├── upgrade_132.html │ ├── upgrade_133.html │ ├── upgrade_140.html │ ├── upgrade_141.html │ ├── upgrade_150.html │ ├── upgrade_152.html │ ├── upgrade_153.html │ ├── upgrade_154.html │ ├── upgrade_160.html │ ├── upgrade_161.html │ ├── upgrade_162.html │ ├── upgrade_163.html │ ├── upgrade_170.html │ ├── upgrade_171.html │ ├── upgrade_172.html │ ├── upgrade_200.html │ ├── upgrade_201.html │ ├── upgrade_202.html │ ├── upgrade_203.html │ ├── upgrade_210.html │ ├── upgrade_211.html │ ├── upgrade_212.html │ ├── upgrade_213.html │ ├── upgrade_214.html │ ├── upgrade_220.html │ ├── upgrade_b11.html │ └── upgrading.html ├── libraries │ ├── benchmark.html │ ├── caching.html │ ├── calendar.html │ ├── cart.html │ ├── config.html │ ├── email.html │ ├── encryption.html │ ├── file_uploading.html │ ├── form_validation.html │ ├── ftp.html │ ├── image_lib.html │ ├── input.html │ ├── javascript.html │ ├── language.html │ ├── loader.html │ ├── migration.html │ ├── output.html │ ├── pagination.html │ ├── parser.html │ ├── security.html │ ├── sessions.html │ ├── table.html │ ├── trackback.html │ ├── typography.html │ ├── unit_testing.html │ ├── uri.html │ ├── user_agent.html │ ├── xmlrpc.html │ └── zip.html ├── license.html ├── nav │ ├── hacks.txt │ ├── moo.fx.js │ ├── nav.js │ ├── prototype.lite.js │ └── user_guide_menu.js ├── overview │ ├── appflow.html │ ├── at_a_glance.html │ ├── cheatsheets.html │ ├── features.html │ ├── getting_started.html │ ├── goals.html │ ├── index.html │ └── mvc.html ├── toc.html ├── tutorial │ ├── conclusion.html │ ├── create_news_items.html │ ├── hard_coded_pages.html │ ├── index.html │ ├── news_section.html │ └── static_pages.html └── userguide.css 48 directories, 355 files
config.php
$ vi config/config.php # base_urlを入力する $ config['base_url'] = 'http://localhost:3000';
apacheの設定
$ vi /etc/httpd/conf/httpd.conf <VirtualHost *:80> ServerAdmin gankai1104@gmail.com DocumentRoot /var/www/test_code ServerName test-code ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common </VirtualHost>
シンボリックリンクの作成
$ cd /var/www $ ln -s ~/Codeigniter/ test-code
以上です。
Vagrantで構築した仮想マシンにDBのdumpファイルを転送する
こんにちはkikeda1104です。
仮想マシン側からdumpファイルを作成して、ローカルにdumpファイルを転送、復元するようにします。
前提
DBからdumpファイルをダウンロード
$ vagrant ssh $ cd $ mysql_dump -u root -h 192.168.1.2 -p --port=3306 my_datadabase >> ~/mydb.sql $ gzip mydb.sql => mydb.sql.gz
vagrantで起動した仮想マシンからファイルをコピーする
$ vagrant ssh-config --host app_server >> ~/.ssh/config $ scp vagrant@app_server:~/mydb.sql.gz ~/mydb.sql.gz $ ungzip mydb.sql.gz
データベースの作成
$ mysql -u root -p $ CREATE DATABASE my_database DEFAULT CHARACTER SET utf8; $ exit
mysql_dumpファイルをローカルのmysqlに復元する
$ mysql -u root -p my_database << mydb.sql
以上です。