« 「MD5」アルゴリズムに欠陥 | メイン | ID&T Radio よい曲がたまにかかる »

PHP 5.0.1でDB_DataObjectが動かない

PHP 5.0.1をいれてDB_DataObjectのcreateTables.phpで
テーブルのクラスを自動作成しようとするとエラー。

PHP 5.0.0でats氏に教わったとおりにやってものうごかず。

モジュールは、pearから
$sudo pear install DB_DataObject
のコマンドでいれ、
setup.iniで対象テーブルを設定するだけなのですが。。。

$ sudo php /usr/local/lib/php/DB/DataObject/createTables.php setup.ini

Fatal error: Method DB_DataObject_Overload::__call() must take exactly 2 arguments in /usr/local/lib/php/DB/DataObject.php on line 191

いろいろ調べたら
Pear-ml Bug #2136 php-5.0.1 seems to break Dataobject
に回答あり。
現状cvsにしかないみたい。

結局、PHP5.0.0に戻してみました。

Perl屋さんの為のPear講座----------------------

まず、pearからDB_DataObjectをインストール

$ sudo pear install DB_DataObject
downloading DB_DataObject-1.7.1.tar ...
Starting to download DB_DataObject-1.7.1.tar (-1 bytes)
.........................................done: 194,048 bytes
requires package `DB' >= 1.6
requires package `Date' >= 1.4.3
DB_DataObject: Dependencies failed

DB,Dateがないと言われるので先にそっちをいれる

$ sudo pear install DB
downloading DB-1.6.5.tar ...
Starting to download DB-1.6.5.tar (-1 bytes)
.............................................................................................done: 573,952 bytes
install ok: DB 1.6.5

$ sudo pear install Date
downloading Date-1.4.3.tar ...
Starting to download Date-1.4.3.tar (-1 bytes)
.................................................................done: 315,392 bytes
install ok: Date 1.4.3

$ sudo pear install DB_DataObject
downloading DB_DataObject-1.7.1.tar ...
Starting to download DB_DataObject-1.7.1.tar (-1 bytes)
.............................done: 194,048 bytes
Optional dependencies:
package `Validate' version >= 0.1.1 is recommended to utilize some features.
install ok: DB_DataObject 1.7.1

$ sudo pear install DB_DataObject
downloading DB_DataObject-1.7.1.tar ...
Starting to download DB_DataObject-1.7.1.tar (-1 bytes)
.............................done: 194,048 bytes
Optional dependencies:
package `Validate' version >= 0.1.1 is recommended to utilize some features.
install ok: DB_DataObject 1.7.1

入りました。
setup.iniを以下のように書いて

$ cat setup.ini
------------------------------------------
[DB]

;portability = 15

[DB_DataObject]

database = mysql://USER:XXXX@localhost/kanshi
schema_location = /home/kanshi/local/DB_DataObject
;links_kanshi = /home/kanshi/local/DB_DataObject/kanshi.links.ini
class_location = /home/kanshi/local/lib/DataObjects
require_prefix = DataObjects/
class_prefix = DataObjects_

以下のコマンドを打つと
$ sudo php /usr/local/lib/php/DB/DataObject/createTables.php setup.ini
DB_DataObject_Generator : 0 : CREATING FOR kanshi

DB_DataObject_Generator : 0 : calling generateDefinitions
DB_DataObject_Generator : 0 : Generating Definitions file:
DB_DataObject_Generator : 0 : Writing ini as /home/kanshi/local/DB_DataObject/kanshi.ini

DB_DataObject_Generator : 0 : calling generateClasses
DB_DataObject_Generator : 0 : writing DataObjects_Site

DB_DataObject_Generator : 0 : DONE

kanshi.iniとSite.phpが作成され準備完了

kanshi.ini---------------
[site]
id = 129
title = 130
url = 194
keyword = 194
emails = 194

[site__keys]
id = N
$ cat Site.php------------
/**
* Table Definition for site
*/
require_once 'DB/DataObject.php';

class DataObjects_Site extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */

var $__table = 'site'; // table name
var $id; // int(11) not_null primary_key auto_increment
var $title; // string(255) not_null
var $url; // blob(65535) not_null blob
var $keyword; // blob(65535) not_null blob
var $emails; // blob(65535) not_null blob

/* Static get */
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Site',$k,$v); }

/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
}

これで、下準備完了。

サイト作成にあたって、ValidationやフォームのFillin(自動入力)の
処理に便利なHTML_QuickFormをインストールします。

pearからのインストールは
$ sudo pear install HTML_QuickForm

downloading HTML_QuickForm-3.2.3.tar ...
Starting to download HTML_QuickForm-3.2.3.tar (-1 bytes)
.............................done: 578,048 bytes
requires package `HTML_Common' >= 1.2.1
HTML_QuickForm: Dependencies failed

依存関係があるので
$ sudo pear install HTML_QuickForm
downloading HTML_QuickForm-3.2.3.tar ...
Starting to download HTML_QuickForm-3.2.3.tar (-1 bytes)
.............................done: 578,048 bytes
requires package `HTML_Common' >= 1.2.1
HTML_QuickForm: Dependencies failed

先にHTML_Commonをインストール
$ sudo pear install HTML_Common
Password:
downloading HTML_Common-1.2.1.tar ...
Starting to download HTML_Common-1.2.1.tar (-1 bytes)
......done: 16,896 bytes
install ok: HTML_Common 1.2.1

HTML_Commonが入ったのでHTML_QuickFormをインストール
$ sudo pear install HTML_QuickForm
downloading HTML_QuickForm-3.2.3.tar ...
Starting to download HTML_QuickForm-3.2.3.tar (-1 bytes)
.............................done: 578,048 bytes
requires package `HTML_Common' >= 1.2.1
HTML_QuickForm: Dependencies failed

あと、テンプレートとロジックを分離するためのエンジン
Smartyを入れておく。
Smartyは、毎回テンプレートを読み込むのではなく、中間ファイルのphpを作成してくれるので
高速である。

SMARTY インストール

これらを使えば、

・ロジックとテンプレートの分離(perlでいうTemplateToolKitのような感じ)
#############################
// Smartyライブラリを読み込む
require('Smarty.class.php');

$smarty = new Smarty;
$smarty->template_dir = '/web/www.mydomain.com/smarty/guestbook/templates/';
$smarty->compile_dir = '/web/www.mydomain.com/smarty/guestbook/templates_c/';
$smarty->config_dir = '/web/www.mydomain.com/smarty/guestbook/configs/';
$smarty->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
$smarty->assign('name','Ned');
$smarty->display('index.tpl');
#############################

・DBの抽象化(perlでいうClass::DBIのような感じ)
#############################
$instance = new DB_DataObject;
$instance -> tableName('xoops_users');
$instance->get("uid",1);
echo $instance->uname;
#############################


・Validationとフォームのフィルイン(perlでいるfillinform?)
のような事ができる。

####################################
入力値チェック(HTML_QuickForm)参考
$form = new HTML_QuickForm('secondForm');

// デフォルトの値を入力
$form->setDefaults(array(
'name' => 'Namahage'
));

// フォームの作成
$form->addElement('text','name','Enter your name:',
array('size' => 50, 'maxlength' => 255));

// バリデーションのルールを設定
$form->addRule('name', 'Please enter your name', 'required', null, 'client');
if ($form->validate()) {
// Formが正しかったらfreezeする
$form->freeze();
}
PEAR HTML_QuickForm入門ガイド
############################

このようなコーディングになります。

perlには、CPANweb好きな人達が集い魅力がありますが、
ちょっとしたサイト構築には、上記のPHPコーディングもよいかも知れません。

というか、優秀な人材が確保できないので、泣く泣くPHPやっている現実もありますがw。


Author: yoshimax Date: 2004年8月24日 13:24 | | Comment (1) | Trackback (0) | Bookmark: このエントリーを含むはてなブックマーク このエントリーをはてなブックマークに追加 Save This Page この記事をクリップ! このエントリーを含むはてなブックマーク

トラックバック

このエントリーのトラックバックURL:
http://www.de4u.net/mt41/mt-tb.cgi/697

コメント (1)

ats:

DB_DataObject 1.7.2 release されてるよん。
この不具合は修正されてるみたい。

About

2004年8月24日 13:24に投稿されたエントリーのページです。

ひとつ前の投稿は「「MD5」アルゴリズムに欠陥」です。

次の投稿は「ID&T Radio よい曲がたまにかかる」です。

他にも多くのエントリーがあります。メインページアーカイブページも見てください。

Technorati

Technorati search

» ここにリンクしているブログ

2008年5月

        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

最近のコメント

アーカイブ

Powered by
Movable Type 4.1