SSブログ
前の10件 | -

サンプルコード修正 [PHP]

Zend Framework入門(8):ビューの処理の流れを理解しよう

サンプルコードを2箇所修正。

 

  • index.php

 

> $view->setEncoding('Shift_JIS');

< $view->setEncoding('UTF-8'); 


  私の環境に合わせて。

 

 

  •  MyFilter.php

 


 

> $buffer = preg_replace('/\<\/p\>/','</i><p>',$buffer);

< $buffer = preg_replace('/\<\/p\>/','</i></p>',$buffer);

 


これは単なる間違い。

 

 

 

 


nice!(0)  コメント(102)  トラックバック(0) 
共通テーマ:学問

MySQL 日本語文字化け [PHP]

Zend Framework入門(7):抽象化レイヤによるデータベースアクセス手法 - Zend_Db(後編) - 

サンプルコードを動作させるためにデータベースを作成したら、データが文字化け。

↓を参考にさせていただく。

http://blog.livedoor.jp/alpha1280/archives/51945214.html 

MySQLの設定(my.ini)に以下の定義を追加して解決。


[mysqld]

character-set-server=utf8
  skip-character-set-client-handshake

[mysql]

character-set-server=utf8
 

 

ただし、サンプルコードある設定ファイル(config/db_info.ini)の 定義を修正する必要があった。

この定義を使ってプログラム内で set names を行っているため。



> character_set = sjis

< character_set = utf8


 

 


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問

アクションヘルパー [PHP]

Zend Framework入門(5):PHPでMVCアプリケーションを構築しよう - Zend_Controller(後編) - 

アクションヘルパーとプラグインについての解説記事。

サンプルコード は問題なく動作し、説明も一応納得したが、

具体的にどういう時に使うのかのイメージがわかず、モヤモヤする。

やはり何か参考書を買わないとだめか?

Amazonで探して目次をのぞいてみると、ヘルパーは特に項目にあげて説明されてない。

http://framework.zend.com/manual/ja/zend.controller.actionhelpers.html

にも「機能追加用」とある。

応用的なものとして、ここはこのまま次に進むべきと判断した。

いずれにしても、そのうち参考書は欲しいな。 

 

オープンソース徹底活用 Zend FrameworkによるWebアプリケーション開発

オープンソース徹底活用 Zend FrameworkによるWebアプリケーション開発

  • 作者: 掌田 津耶乃
  • 出版社/メーカー: 秀和システム
  • 発売日: 2009/06
  • メディア: 単行本
Zend Framework 徹底マスター

Zend Framework 徹底マスター

  • 作者: 藤野 真吾
  • 出版社/メーカー: ソーテック社
  • 発売日: 2009/04/11
  • メディア: 単行本(ソフトカバー)
Zend Framework徹底入門

Zend Framework徹底入門

  • 作者: 山田 祥寛
  • 出版社/メーカー: 翔泳社
  • 発売日: 2008/09/18
  • メディア: 大型本

 


nice!(1)  コメント(0)  トラックバック(0) 
共通テーマ:学問

Smartyでケータイサイトを作ってみる [PHP]

第14回 Smartyでケータイサイトを作ってみる

やっと最終回。

とりあえずやってみるが、絵文字のところはエミュレータからの絵文字入力ができないので試せなかった。

また、resource.var.php もエラーがとれず、string:をstringリソースを使うように修正。

携帯エミュレータは Firefox + FirefoxのアドオンFireMobileSimulator をインストールする。

http://firemobilesimulator.org/ 

 

  • ディレクトリ構成

 

(太字は記事にはなく、最初から自分で作ったもの)


[htdocs]
  |--- post.php
[smartyapp]
  |--- [cache]
  |--- [configs]
  |--- [libs]
  |      |--- EmojiTable.class.php
  |--- [plugins]
  |      |--- function.emoji.php
  |      |--- outputfilter.shiftjis.php
  |      |--- outputfilter.xmldoctype.php
  |      |--- resource.var.php
  |--- [templates]
  |      |--- template.tpl
  |--- [templates_c]

 

よくわかってない部分もあるが、携帯サイトの雰囲気はつかめたので、とりあえず終了。

機会があったら、ちゃんとやってみることに。

 


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問

Zend FrameworkでSmartyを使う環境を作る [PHP]

サーバが復旧したようなので、Smartyの続きをやる。

第12回 Smartyとフレームワーク(その2:Zend Framework編) 

これだけだと、何をどこにおくかよくわからなかったので。。。↓ここも参考にさせてもらった。 

http://helog.jp/php/zend-framework/984/ 

ディレクトリ構成は下記の通りに変更。適宜index.phpのディレクトリ指定部分を修正。

 


 

htdocs(DocumentRoot)
   |--- index.php
   |--- [application]
            |--- [controllers]
            |       |--- TestController.php
            |--- [smarty]
            |       |--- [cache]
            |       |--- [configs]
            |       |--- [templates]
            |       |         |--- [test]
            |       |                 |--- hello.tpl
            |       |--- [templates_c]
            |       |--- Zend_View_Smarty.class.php
            |--- [views]
                   |--- [scripts]

 


 

ディレクトリ以外に、修正が必要だったのは以下の点。

(1) 以下のNOticeメッセージが出る

 



Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader...

 


 index.phpを下記の通り修正

 


(削除)

 

  include "Zend/Loader.php";

   Zend_Loader::registerAutoload();


(追加)

require_once('Zend/Loader/Autoloader.php');

  $autoloader = Zend_Loader_Autoloader::getInstance();

  $autoloader->setFallbackAutoloader(true);

 



(2) 下記のWarningメッセージが出る

 

 



Warning: include_once(Smarty\Internal\Data.php) [function.include-once]: failed to open stream: No such file or directory

 


 index.phpを下記の通り修正


 (追加)

  Zend_Loader_Autoloader::getInstance()->pushAutoloader(NULL, 'Smarty_' );

 



以上で、サンプルコードが無事起動。

 

ちなみに、起動は http://localhost/test/hello/ で行う。 

 

 

 

 

 

 


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問

ルーティング [PHP]

Zend Framework入門(4):PHPでMVCアプリケーションを構築しよう - Zend_Controller(中編) -

ルーティングに苦戦。

以前に設定した環境では、動作しない模様。  

DocumentRoot で動作させないと、index.phpを直接起動させるぶんにはいいが、ルーティングが機能しない。

なので、以下の通り対応。スマートではないが、こだわると横道にそれてしまうので。

(1) ZendServer(vertial server) の DocumentRoot を変更する。


<VirtualHost *:10081>
Alias /ZendServer "C:\Zend\ZendServer\GUI\html"
#DocumentRoot "C:\Zend\ZendServer\GUI\html"
  DocumentRoot "C:\dvl_php\htdocs"
RewriteEngine On 
#RewriteRule ^/$ /ZendServer/ [R]
RewriteRule ^/Login$ /ZendServer/Login [R]
  <Directory "C:\Zend\ZendServer\GUI\html">
    AllowOverride All
    Allow from all
  </Directory>
  
  <Directory "C:\dvl_php\htdocs">
    AllowOverride All
    Allow from all
    </Directory>

</VirtualHost>


 

(2) eclipse環境から実行環境へファイルをコピーするシェルを作成し、eclipseプロジェクトに配置。

windows powershell で作成。

下記を管理者権限で実行しておかないと、エラーとなる。 

 


 

PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned

 


 

(3) eclipseの「外部ツールの起動」により、上記のスクリプトを実行。

(4) テスト用のhtmlを作成し、そこからリンクを開くことでアプリケーションを実行。

☆eclipseの「実行」「デバッグ」が使用できない。

  デバッガを使いたくなったらどうするか?

 

☆(2)~(4)はプロジェクト毎に作成し、ソースを修正したり、動作させるプロジェクトを変える度にスクリプトを実行する。

 

 

それと、サンプルコードに下記の行は不要とあったが、ないとエラーとなるので必要と思われる。



require_once 'Zend/Controller/Router/Route/Static.php';



 

 


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問

Controller, Action, View など [PHP]

Zend Framework入門(3):PHPでMVCアプリケーションを構築しよう - Zend_Controller(前編) - 

Controller, Action, Viewなどが どう関連しているのかをメモ。 

(1) フロントコントローラでアクションコントローラ名を設定

setDefaultControllerName(アクションコントローラ名


(2) アクションコントローラのファイル名は、(1)で定義したアクションコントローラ名により決定

 <アクションコントローラ名>Controller.php

☆ <アクションコントローラ名>の先頭は大文字

☆ これを行わないとデフォルト(index)となる  


(3) フロントコントローラでアクション名を設定

setDefaultAction(アクション名)

☆ これを行わないとデフォルト(index)となる 

(4) (3)で設定したアクション名により、アクションコントローラのアクションメソッド作成

メソッド名:  <アクション名>Action

☆ <アクション名>の先頭は小文字

(5) Viewは下記の場所・名前で作成

  views/scripts/<アクションコントローラ名>/<アクション名>.phtml 

 

 

以上をふまえて、記事の http://localhost/initsample/にアクセスしてみてください」 に答えるには、下記の修正を行う。


 (hodocs/index.php)


>  $front->setDefaultControllerName('wings');

<  $front->setDefaultControllerName('initsample'); 

 

 



また、http://localhost/initsample/index2にアクセスしてみてください」 の場合は、上記の修正に加えて、下記の修正。

 



 

(hodocs/index.php)


>  $front->setDefaultAction('codezine');

 

<  $front->setDefaultAction('index2');

 

 

 


 

ここまでくれば大丈夫。 「試しに「http://localhost/initsample/wings」へアクセスしてみる」 には 

 



>  $front->setDefaultAction('index2');

 

<   $front->setDefaultAction('wings');

 


 

 


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問

Zend Framework を使ってみる [PHP]

第12回 Smartyとフレームワーク(その2:Zend Framework編) 

をやる予定だったが、サーバが障害中でできない。

ので、インストール・環境設定もかねてこちら↓をやる。

Zend Framework入門(1):フレームワークの全体像とインストール  

↓ここから 【Zend Framework + Zend Server Community Edition(CE)】 をダウンロード。

http://framework.zend.com/download/latest

Zend FrameworkだけでもOKなようだが、上記のZend Server も一緒のほうだと

設定は特にしなくてもOK.

一応、HPに書いてある設定部分を確認する。

 



(1) C:\Zend\ZendServer\etc\php.ini のinclude_path

 [Zend]

include_path=".;C:\Zend\ZendServer\share\ZendFramework\library"

 

 


(2) C:\Zend\Apache2\conf\httpd.conf

 

LoadModule rewrite_module modules/mod_rewrite.so

が有効(コメントがはずれていること)

 


(3) C:\Zend\Apache2\conf\zend.conf
 
下記が定義されていること 
 
<Directory "C:\Zend\ZendServer\GUI\html">
  AllowOverride All Allow from all
</Directory>
 
 

(4) C:\Zend\ZendServer\GUI\html\.htaccess

下記が定義されていること

 RewriteEngine on

 RewriteBase /ZendServer/

RewriteRule !\.(xml|swf|swz|html|htm|pdf|php|js|ico|txt|gif|jpg|png|css|rss|zip|tar\.gz)$ index.php

 




ちなみに Zend Framework の場所は C:\Zend\ZendServer\share\ZendFramework 

 


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問

CakePHPでSmartyを使う環境を作る [PHP]

第11回 Smartyとフレームワーク(その1:CakePHP編)  

 

参考HP: http://www.phpbook.jp/cakephp/install/

SmartyViewのダウンロード。上記のサイトにあったURLはもう存在しないようなので、

http://blog.ecworks.jp/archives/34 こちらから。ReadMeの通り設定。

ただ、smarty1.2用とのことで、そのままでは動作しない。(自分の環境はSmarty1.3) 

まず、SmartyViewのサンプルを動作させるため、下記にアクセス(cakephpはcakephpをインストールした場所)。

http://localhost/cakephp/mypages/index 

 

下記エラー発生。



Fatal error: Class 'Smarty' not found SmartyView


 

バージョンの違いのため?

ReadMeに書いてあるフォルダ構成と自分の環境が異なるため、無理やり変更したら、動いた。


 

  %apache_dir%\htdocs\cakephp\app\vendors\smarty\lib の中身を

  %apache_dir%\htdocs\cakephp\app\vendors\smarty へ。

(Smarty.class.php, pluginsフォルダ, syspluginsフォルダ など) 


 

 まだ以下のエラーが表示される。



Notice (1024): function call 'assign_by_ref' is unknown or deprecated, use 'assignByRef' [APP\vendors\smarty\sysplugins\smarty_internal_data.php, line 79]

Notice (8): Undefined property: SmartyView::$pageTitle [APP\views\smarty.php, line 163]

Notice (8): Undefined property: SmartyView::$pageTitle [APP\views\smarty.php, line 164] Testing SmartyView

Copyright 2008, ECWorks.


 

Smarty.class.phpを下記の通り修正してOK。

 



> $pageTitle = $this->pageTitle


< $pageTitle = @$this->pageTitle


 

> $this->smarty->assign_by_ref('view', $this);

< $this->smarty->assignByRef('view', $this); 

 


 

SmartyViewのサンプルが動いたので、今度は 第11回 Smartyとフレームワーク(その1:CakePHP編) の

コードを動作させてみる。

と、日付表示の部分が、表示されない。



  (smartyのテンプレート)
 
今日は{$smarty.now|date_format:'%Y年%m月%d日'}です。
 

  (実行結果) 

今日はです。 

 


 

以下を試す。 

 

  •  phpでの日付出力(date関数) -> OK
  • date_formatのパラメータを'%D'に変更 -> NG
  • date_format:'%Y年%m月%d日' を "date_format:'%Y年%m月%d日"に変更 -> NG
  • date_formatを行わないでそのまま出力 -> OK
 
結果から、date_formatが動いていないらしいと判断するが、行き詰まる。
smartyのバージョンや無理やり変更した環境のせいか?
 
とりあえずここで終了。
cakePHPは選択肢から消えたかな。

 

 

 



nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問

smartyのget_config_vars()でNoticeエラー [PHP]

第6回 Smartyを使って実用的なページを作ってみる(その2)

前回と同様。サンプルプログラムの↓でNoticeエラー発生。


 

> $smarty->config_load ( 'typeRequest' );

  < $smarty->getConfigVars( 'typeRequest' );

 


 

フィルタ登録のAPIは引数も変更になっているらしい。 


 

  [新月]プリフィルタ 

> $smarty->register_prefilter('my_prefilter');

  < $smarty->registerFilter('pre', 'my_prefilter');

 


 

  [新月]ポストフィルタ

> $smarty->register_postfilter('my_postfilter');

  < $smarty->registerFilter('post', 'my_prefilter');

 


 

  [新月]アウトプットフィルタ 

> $smarty->register_outputfilter('my_outputfilter');

  < $smarty->registerFilter('output', 'my_outputfilter');

 


 

 第1引数には、’variable’ という指定もできるらしいけど、どんな時に使うか不明。

http://www.smarty.net/docs/ja/api.register.filter.tpl

 


nice!(0)  コメント(0)  トラックバック(0) 
共通テーマ:学問
前の10件 | -

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。