<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>@blog.justoneplanet.info &#187; ZendFramework</title>
	<atom:link href="http://blog.justoneplanet.info/category/computer-language/php/zendframework/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.justoneplanet.info</link>
	<description>日々勉強</description>
	<lastBuildDate>Wed, 08 Feb 2012 02:57:17 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Zend_Validateをつかってみる</title>
		<link>http://blog.justoneplanet.info/2010/08/07/zend_validate%e3%82%92%e3%81%a4%e3%81%8b%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/08/07/zend_validate%e3%82%92%e3%81%a4%e3%81%8b%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 17:10:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2820</guid>
		<description><![CDATA[■使用方法 以下のようにしてバリデートする。 $validator = Zend_Validate_EmailAddress(); if($validator-&#62;isValid($str)){ //success  [...]]]></description>
			<content:encoded><![CDATA[<h3>■使用方法</h3>
<p>以下のようにしてバリデートする。</p>
<pre class="brush: php;">
$validator = Zend_Validate_EmailAddress();
if($validator-&gt;isValid($str)){
    //success
}
else{//falure
    $this-&gt;view-&gt;error = $validator-&gt;getMessages();//array
}
</pre>
<h4>エラーメッセージの変更</h4>
<p>以下のようにするとエラーメッセージを変更することができる。</p>
<pre class="brush: php;">
$validator = new Zend_Validate_StringLength(8);
$validator-&gt;setMessage(
    'コラァ=3',
    Zend_Validate_StringLength::TOO_SHORT
);
if($validator-&gt;isValid($str)){
    //success
}
else{
    $this-&gt;view-&gt;error = $validator-&gt;getMessages();//array
}
</pre>
<p>以下のように数パターンエラーメッセージを指定することも考えられる。</p>
<pre class="brush: php;">
$validator = new Zend_Validate_StringLength(array(
    'min' =&gt; 2,
    'max' =&gt; 10
));
$validator-&gt;setMessage(
    Zend_Validate_StringLength::TOO_SHORT =&gt; 'コラァ=3',
    Zend_Validate_StringLength::TOO_LONG =&gt; 'ゴルァ=3'
);
if($validator-&gt;isValid($str)){
    //success
}
else{
    $this-&gt;view-&gt;error = $validator-&gt;getMessages();//array
}
</pre>
<h3>■静的に扱う</h3>
<p>以下のようにZend_Validateクラスの静的メソッドを用いてバリデートすることもできる。</p>
<pre class="brush: php;">
if(Zend_Validate::is($str, 'EmailAddress')){
    //success
}
</pre>
<pre class="brush: php;">
if(Zend_Validate::is($str, 'StringLength', array('min' =&gt; 10, 'max' =&gt; 20))){
    //success
}
</pre>
<h3>■多言語対応</h3>
<p>デフォルトのメッセージはベタ＆英語なのでパンチの利いたセリフが必要だ。</p>
<pre class="brush: php;">
$validator = new Zend_Validate_EmailAddress();
$validator-&gt;setTranslator(new Zend_Translate(
    'array',
    array(
        Zend_Validate_Hostname::UNKNOWN_TLD =&gt; 'そんなトップレベルドメインしらねーぜぃ'
    ),
    'en'
));
if($validator-&gt;isValid()){
    //success
}
else{
    //failure
}
</pre>
<p>以下のようにして一度に適用できる。</p>
<pre class="brush: php;">
Zend_Validate::setDefaultTranslator(new Zend_Translate(
    'array',
    array(
        Zend_Validate_Hostname::UNKNOWN_TLD =&gt; 'そんなトップレベルドメインしらねーぜぃ'
    ),
    'en'
));
</pre>
<p>バリデートのクラスはすごくいっぱい。</p>
<p>http://framework.zend.com/manual/ja/zend.validate.set.html</p>
<h3>■バリデータチェーン</h3>
<p>以下のようにして1つのインスタンスに複数のルールを付加できる。</p>
<pre class="brush: php;">
$validator = new Zend_Validate();
$validator-&gt;addValidator(new Zend_Validate_Alnum());
$validator-&gt;addValidator(new Zend_Validate_StringLength(array(
    'min' =&gt; 10,
    'max' =&gt; 20
)));
</pre>
<h3>■自作バリデータ</h3>
<p>めんどくさいけど作ってみる。以下のようにZend_Validate_Abstractを継承して自作バリデータを作ることができる。</p>
<pre class="brush: php;">
class MyValidate_Array extends Zend_Validate_Abstract
{
    const ARRAY = 'array';
    protected $_messageTemplates = array(
        self::ARRAY = &quot;'%value'は配列を入れてね！&quot;
    );
    public function isValid($value)
    {
        if(!is_array($value)){
            $this-&gt;_error(self::ARRAY);
            return false;
        }
        else{
            return true;
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/08/07/zend_validate%e3%82%92%e3%81%a4%e3%81%8b%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Layoutを触ってみる</title>
		<link>http://blog.justoneplanet.info/2010/07/25/zend_layout%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/07/25/zend_layout%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 19:55:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2786</guid>
		<description><![CDATA[■フロントコントローラ 大枠（レイアウト部分）が置いてあるディレクトリのパスはここで指定してもよいと思う。 /public_html/index.php Zend_Layout::startMvc(array( 'lay [...]]]></description>
			<content:encoded><![CDATA[<h3>■フロントコントローラ</h3>
<p>大枠（レイアウト部分）が置いてあるディレクトリのパスはここで指定してもよいと思う。</p>
<h4>/public_html/index.php</h4>
<pre class="brush: php;">
Zend_Layout::startMvc(array(
    'layout'     =&gt; 'layout',// layout.phtml
    'layoutPath' =&gt; '../application/modules/admin/views/layouts/'// path
));
$front = Zend_Controller_Front::getInstance();
</pre>
<h3>■コントローラ</h3>
<p>まぁ大体一つのコントローラ内でレイアウトが変わるなんて事はないから、initで設定してイイよね。</p>
<pre class="brush: php;">
    /**
     * init
     * @return void
     */
    public function init()
    {
        $this-&gt;_helper-&gt;layout-&gt;setLayout('layout');// layout.phtml
        //$this-&gt;_helper-&gt;layout-&gt;setLayoutPath('../application');// path
        $this-&gt;_helper-&gt;layout-&gt;assign('menu', $this-&gt;view-&gt;render('menu.phtml'));
    }
</pre>
<p>こんな感じにしておけば、以下の様な感じでイケる！</p>
<h3>■ビュー</h3>
<p>/application/modules/admin/views/scripts/index/index.phtmlの部分は$this-&gt;layout()-&gt;contentに出力される。</p>
<h4>/application/modules/admin/views/layouts/layout.phtml</h4>
<pre class="brush: php;">
&lt;div id=&quot;sidebar&quot;&gt;
&lt;?php echo $this-&gt;layout()-&gt;menu ?&gt;
&lt;/div&gt;
&lt;div id=&quot;main&quot;&gt;
&lt;?php echo $this-&gt;layout()-&gt;content ?&gt;
&lt;/div&gt;
</pre>
<h3>■その他の設定</h3>
<pre class="brush: php;">
    /**
     * init
     * @return void
     */
    public function init()
    {
        $this-&gt;_helper-&gt;layout-&gt;setLayout('layout');// layout.phtml
        $this-&gt;_helper-&gt;layout-&gt;assign('menu', $this-&gt;view-&gt;render('menu.phtml'));
        $this-&gt;_helper-&gt;layout-&gt;disableLayout();// レイアウトを無効化できる
        $this-&gt;_helper-&gt;layout-&gt;setContentKey('main');// デフォルト名$this-&gt;layout()-&gt;contentを$this-&gt;layout()-&gt;mainに変更できる
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/07/25/zend_layout%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Formをもっと触ってみる</title>
		<link>http://blog.justoneplanet.info/2010/07/24/zend_form%e3%82%92%e3%82%82%e3%81%a3%e3%81%a8%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/07/24/zend_form%e3%82%92%e3%82%82%e3%81%a3%e3%81%a8%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 18:22:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2767</guid>
		<description><![CDATA[特定の要素をグルーピングしたい時だってある。 &#60;?php class Admin_IndexController extends Zend_Controller_Action { public function i [...]]]></description>
			<content:encoded><![CDATA[<p>特定の要素をグルーピングしたい時だってある。</p>
<pre class="brush: php;">
&lt;?php
class Admin_IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this-&gt;view-&gt;form = $this-&gt;_createForm();
    }
    public function registerAction()
    {
        $form = $this-&gt;createForm();
        if(!form-&gt;isValid($this-&gt;_getAllParams())){// error
            $this-&gt;view-&gt;assign('form', $form);
            return $this-&gt;render('index');
        }
        else{// success
            $this-&gt;_dbh-&gt;register($form-&gt;getValues());
        }
    }
    private function _createForm()
    {
        $form = new Zend_Form();
        $form-&gt;setAction('/admin/index/register/')-&gt;setMethod('post');
        $form-&gt;addElement(
            'text',
            'name',
            array(
                'validators' =&gt; array(
                    array('Regex', false, array('/^[a-z]/i'))
                ),
                'label'      =&gt; 'Name : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addElement(
            'password',
            'pass',
            array(
                'validators' =&gt; array(
                    'Alnum'
                ),
                'label'      =&gt; 'Password : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addDisplayGroup(
            array(
                'name',
                'pass'
            ),
            'login',
            array(
                'disableLoadDefaultDecorators' =&gt; false
            )
        );
        $form-&gt;addElement('hash', 'checkHash');
        $form-&gt;addElement('submit', '送信');
        return $form;
    }
}
?&gt;
</pre>
<p>上述のようにしてグループ毎にfieldsetで括ることができる。addDisplayGroupは要素を定義した直後にコールしないとフォームの要素の順序が変わってしまうので注意が必要である。</p>
<h4>出力html</h4>
<pre class="brush: xml;">
&lt;form enctype=&quot;application/x-www-form-urlencoded&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
&lt;dl class=&quot;zend_form&quot;&gt;
&lt;dt id=&quot;login-label&quot;&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dd id=&quot;login-element&quot;&gt;&lt;fieldset id=&quot;fieldset-login&quot;&gt;
&lt;dl&gt;
&lt;dt id=&quot;name-label&quot;&gt;&lt;label for=&quot;name&quot; class=&quot;required&quot;&gt;Name :&lt;/label&gt;&lt;/dt&gt;
&lt;dd id=&quot;name-element&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; value=&quot;&quot;&gt;&lt;/dd&gt;
&lt;dt id=&quot;pass-label&quot;&gt;&lt;label for=&quot;pass&quot; class=&quot;required&quot;&gt;Password :&lt;/label&gt;&lt;/dt&gt;
&lt;dd id=&quot;pass-element&quot;&gt;&lt;input type=&quot;password&quot; name=&quot;pass&quot; id=&quot;pass&quot; value=&quot;&quot;&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;/fieldset&gt;&lt;/dd&gt;
&lt;dt id=&quot;checkHash-label&quot;&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dd id=&quot;checkHash-element&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;checkHash&quot; value=&quot;c15806d5c0f9bc7f6b414ba2cf40468d&quot; id=&quot;checkHash&quot;&gt;&lt;/dd&gt;
&lt;dt id=&quot;送信-label&quot;&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dd id=&quot;送信-element&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;送信&quot; id=&quot;送信&quot; value=&quot;送信&quot;&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;/form&gt;
</pre>
<p>なかなか構造化された綺麗なHTMLが出力される！</p>
<dl>
<dt>Zend_Form::addElement(string $type, string $name, array $options);</dt>
<dd>第一引数でtype属性を指定、第二引数でname属性、第三引数でバリデータやフィルタのオプション設定をする</dd>
<dt>Zend_Form::addDisplayGroup(array $elementNames, string $fieldsetName, array options);</dt>
<dd>第一引数で要素のname属性を配列で指定、第二引数でfieldsetの任意の名前、第三引数でオプション設定をする</dd>
</dl>
<h3>■フォームのデコレータ</h3>
<p>勝手にタグがついて全体をfieldsetで括ってくれて便利なんだが余計なお世話になるときだってある。そこでデフォルトでフォームに付加されるHTMLタグを変更する。</p>
<pre class="brush: php;">
&lt;?php
class Admin_IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this-&gt;view-&gt;form = $this-&gt;_createForm();
    }
    public function registerAction()
    {
        $form = $this-&gt;createForm();
        if(!form-&gt;isValid($this-&gt;_getAllParams())){// error
            $this-&gt;view-&gt;assign('form', $form);
            return $this-&gt;render('index');
        }
        else{// success
            $this-&gt;_dbh-&gt;register($form-&gt;getValues());
        }
    }
    private function _createForm()
    {
        $form = new Zend_Form();
        $form-&gt;setAction('/admin/index/register/')-&gt;setMethod('post');
        $form-&gt;addElement(
            'text',
            'name',
            array(
                'validators' =&gt; array(
                    array('Regex', false, array('/^[a-z]/i'))
                ),
                'label'      =&gt; 'Name : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addElement(
            'password',
            'pass',
            array(
                'validators' =&gt; array(
                    'Alnum'
                ),
                'label'      =&gt; 'Password : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addElement('hash', 'checkHash');
        $form-&gt;addElement('submit', '送信');
        $form-&gt;clearDecorators();
        $form-&gt;addDecorator('FormElements')-&gt;addDecorator('HtmlTag', array('tag' =&gt; 'ul', 'class' =&gt; 'form'))-&gt;addDecorator('Form');
        $form-&gt;setElementDecorators(array('ViewHelper', 'Label', array('HtmlTag', array('tag' =&gt; 'li'))));
        return $form;
    }
}
?&gt;
</pre>
<h4>出力コード</h4>
<pre class="brush: xml;">
&lt;form enctype=&quot;application/x-www-form-urlencoded&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
&lt;ul class=&quot;form&quot;&gt;
&lt;li&gt;&lt;label for=&quot;name&quot; class=&quot;required&quot;&gt;Name :&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; value=&quot;&quot;&gt;&lt;/li&gt;
&lt;li&gt;&lt;label for=&quot;pass&quot; class=&quot;required&quot;&gt;Password :&lt;/label&gt;&lt;input type=&quot;password&quot; name=&quot;pass&quot; id=&quot;pass&quot; value=&quot;&quot;&gt;&lt;/li&gt;
&lt;li&gt;&lt;input type=&quot;hidden&quot; name=&quot;checkHash&quot; value=&quot;f2bcb658321fb39cdc0bd92c61210f7d&quot; id=&quot;checkHash&quot;&gt;&lt;/li&gt;
&lt;li&gt;&lt;label for=&quot;送信&quot; class=&quot;optional&quot;&gt;送信&lt;/label&gt;&lt;input type=&quot;submit&quot; name=&quot;送信&quot; id=&quot;送信&quot; value=&quot;送信&quot;&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/form&gt;
</pre>
<dl>
<dt>Zend_Form::addDecorator(string $className, , array $options = null);</dt>
<dd></dd>
<dt>Zend_Form::addDecorators(array $decorators);</dt>
<dd></dd>
</dl>
<div class="kakomi">
<p>いろんなデコレータ</p>
<pre class="brush: php;">
    private function _createForm()
    {
        $form = new Zend_Form();
        $form-&gt;setAction('/admin/index/register/')-&gt;setMethod('post');
        $form-&gt;addElement(
            'text',
            'name',
            array(
                'validators' =&gt; array(
                    array('Regex', false, array('/^[a-z]/i'))
                ),
                'label'      =&gt; 'Name : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addElement(
            'password',
            'pass',
            array(
                'validators' =&gt; array(
                    'Alnum'
                ),
                'label'      =&gt; 'Password : ',
                'required'   =&gt; true
            )
        );

        $name = $form-&gt;getElement('name');
        $name-&gt;setDescription('&lt;span class=&quot;description&quot;&gt;名前をいれる感じで&lt;/span&gt;');
        $name-&gt;addDecorator(//&lt;p&gt;
            'description',
            array(
                'class'  =&gt; 'descrition',
                'escape' =&gt; false
            )
        );

        $form-&gt;addElement('hash', 'checkHash');
        $form-&gt;addElement('submit', '送信');
        $form-&gt;clearDecorators();
        $form-&gt;addDecorator('FormElements')-&gt;addDecorator('HtmlTag', array('tag' =&gt; 'ul', 'class' =&gt; 'form'))-&gt;addDecorator('Form');
        $form-&gt;setElementDecorators(array('ViewHelper', 'Label', array('HtmlTag', array('tag' =&gt; 'li'))));
        return $form;
    }
</pre>
<h4>出力HTML</h4>
<pre class="brush: xml;">
&lt;form enctype=&quot;application/x-www-form-urlencoded&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
&lt;ul class=&quot;form&quot;&gt;
&lt;li&gt;&lt;label for=&quot;name&quot; class=&quot;required&quot;&gt;Name :&lt;/label&gt;
&lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; value=&quot;&quot;&gt;&lt;/li&gt;
&lt;p class=&quot;descrition_class&quot;&gt;&lt;span class=&quot;description&quot;&gt;名前をいれる感じで&lt;/span&gt;&lt;/p&gt;
&lt;li&gt;&lt;label for=&quot;pass&quot; class=&quot;required&quot;&gt;Password :&lt;/label&gt;
&lt;input type=&quot;password&quot; name=&quot;pass&quot; id=&quot;pass&quot; value=&quot;&quot;&gt;&lt;/li&gt;
&lt;li&gt;&lt;input type=&quot;hidden&quot; name=&quot;checkHash&quot; value=&quot;0162b9bd58af60eb903fe52237bc6a8f&quot; id=&quot;checkHash&quot;&gt;&lt;/li&gt;
&lt;li&gt;&lt;label for=&quot;送信&quot; class=&quot;optional&quot;&gt;送信&lt;/label&gt;
&lt;input type=&quot;submit&quot; name=&quot;送信&quot; id=&quot;送信&quot; value=&quot;送信&quot;&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/form&gt;
</pre>
</div>
<h3>■自作デコレータ</h3>
<p>以下のようにZend_Form_Decorator_Abstractを継承してあげればオリジナルデコレータができる！</p>
<p>../application/decorators/Original.php</p>
<pre class="brush: php;">
&lt;?php
class Jop_Decorator_Original extends Zend_Form_Decorator_Abstract
{
    public function render($content)
    {
         return &quot;&lt;span&gt;{$content}&lt;/span&gt;&quot;;
    }
}
?&gt;
</pre>
<p>以下のようにして使用する。</p>
<pre class="brush: php;">
    private function _createForm()
    {
        $form = new Zend_Form();
        $form-&gt;setAction('/admin/index/register/')-&gt;setMethod('post');
        $form-&gt;addPrefixPath('Jop_Decorator', '../application/decorators', 'decorator');
        //追加したフォーム要素に登録
        //$form-&gt;addElementPrefixPath('Jop_Decorator', 'path', 'decorator');
        $form-&gt;addElement(
            'text',
            'name',
            array(
                'validators' =&gt; array(
                    array('Regex', false, array('/^[a-z]/i'))
                ),
                'label'      =&gt; 'Name : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addElement(
            'password',
            'pass',
            array(
                'validators' =&gt; array(
                    'Alnum'
                ),
                'label'      =&gt; 'Password : ',
                'required'   =&gt; true
            )
        );

        $name = $form-&gt;getElement('name');
        //個別のフォーム要素に加える
        $name-&gt;addPrefixPath('Jop_Decorator', '../applications/decorators', 'decorator');
        $name-&gt;addDecorator('Original');

        $form-&gt;addElement('hash', 'checkHash');
        $form-&gt;addElement('submit', '送信');
        return $form;
    }
</pre>
<p>以下のようにspanで括られて出力される。</p>
<pre class="brush: xml;">
&lt;form enctype=&quot;application/x-www-form-urlencoded&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
&lt;dl class=&quot;zend_form&quot;&gt;
&lt;span&gt;&lt;dt id=&quot;name-label&quot;&gt;&lt;label for=&quot;name&quot; class=&quot;required&quot;&gt;Name :&lt;/label&gt;&lt;/dt&gt;
&lt;dd id=&quot;name-element&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; value=&quot;&quot;&gt;&lt;/dd&gt;&lt;/span&gt;
&lt;dt id=&quot;pass-label&quot;&gt;&lt;label for=&quot;pass&quot; class=&quot;required&quot;&gt;Password :&lt;/label&gt;&lt;/dt&gt;
&lt;dd id=&quot;pass-element&quot;&gt;&lt;input type=&quot;password&quot; name=&quot;pass&quot; id=&quot;pass&quot; value=&quot;&quot;&gt;&lt;/dd&gt;
&lt;dt id=&quot;checkHash-label&quot;&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dd id=&quot;checkHash-element&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;checkHash&quot; value=&quot;784473de7bc7e8048eff4538060bce03&quot; id=&quot;checkHash&quot;&gt;&lt;/dd&gt;
&lt;dt id=&quot;送信-label&quot;&gt;&amp;nbsp;&lt;/dt&gt;
&lt;dd id=&quot;送信-element&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;送信&quot; id=&quot;送信&quot; value=&quot;送信&quot;&gt;&lt;/dd&gt;
&lt;/dl&gt;
&lt;/form&gt;
</pre>
<h3>■エラーメッセージの日本語化</h3>
<p>以下のようにすると対応するエラーメッセージを日本語化できる。</p>
<pre class="brush: php;">
    private function _createForm()
    {
        $form = new Zend_Form();
        $form-&gt;setAction('/admin/index/register/')-&gt;setMethod('post');
        $form-&gt;addElement(
            'text',
            'name',
            array(
                'validators' =&gt; array(
                    array('Regex', false, array('/^[a-z]/i'))
                ),
                'label'      =&gt; 'Name : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addElement(
            'password',
            'pass',
            array(
                'validators' =&gt; array(
                    'Alnum'
                ),
                'label'      =&gt; 'Password : ',
                'required'   =&gt; true
            )
        );
        $form-&gt;addElement('hash', 'checkHash');
        $form-&gt;addElement('submit', '送信');
        $adapter = new Zend_Translate(
            'array',
            array(
                &quot;'%value%' has not only alphabetic and digit characters&quot; =&gt; &quot;'%value%' に英数字以外の文字が含まれています&quot;,
                &quot;'%value%' does not match against pattern '%pattern%'&quot;   =&gt; &quot;'%value%' は '%pattern%' にマッチしません。&quot;
            )
        );
        $form-&gt;setTranslator($adapter);
        return $form;
    }
</pre>
<p>全てのフォームに適用する場合は以下のようにする。
<pre class="brush: php;">
Zend_Form::setDefaultTranslator($adapter);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/07/24/zend_form%e3%82%92%e3%82%82%e3%81%a3%e3%81%a8%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Formを触ってみる</title>
		<link>http://blog.justoneplanet.info/2010/07/21/zend_form%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/07/21/zend_form%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 14:44:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2761</guid>
		<description><![CDATA[■結論 コントローラ &#60;?php class Admin_IndexController extends Zend_Controller_Action { public function indexAction() [...]]]></description>
			<content:encoded><![CDATA[<h3>■結論</h3>
<h4>コントローラ</h4>
<pre class="brush: php;">
&lt;?php
class Admin_IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $form = $this-&gt;createForm();
        $this-&gt;view-&gt;form = $form;
    }
    public function registerAction()
    {
        $form = $this-&gt;createForm();
        if(!$form-&gt;isValid($this-&gt;_getAllParams())){// error
            $this-&gt;view-&gt;assign('form', $form);
            return $this-&gt;render('index');
        }
        else{// success
            $this-&gt;_dbh-&gt;register($form-&gt;getValues());
        }
    }
    private function createForm()
    {
        $form = new Zend_Form();
        $form-&gt;addElement(
            'text',
            'name',
            array(
                'validators' =&gt; array(
                    array('Regex', false, array('/^[a-z]/i'))
                ),
                'label'      =&gt; 'Name : ',
                'required'   =&gt; true
                'filters'    =&gt; array(
                    'StringToLower',
                    'StripTags'
                )
            )
        );
        $form-&gt;addElement('hash', 'checkHash');
        $form-&gt;addElement('submit', '送信');
        return $form;
    }
}
?&gt;
</pre>
<h4>index.phtml</h4>
<pre class="brush: php;">
&lt;?php echo $this-&gt;form; ?&gt;
</pre>
<div class="kakomi">
<p>最初にZend_Formのインスタンスを作成する。</p>
<h4>他のモジュールとの連携</h4>
<ul>
<li> バリデート（Zend_Validate）</li>
<li>フィルタリング（Zend_Filter）</li>
</div>
<h3>■Zend_Form</h3>
<h4>コントローラ</h4>
<pre class="brush: php;">
$form = new Zend_Form();
$form-&gt;setAction('/admin/index/register/')-&gt;setMethod('post');
$this-&gt;view-&gt;form = $form;
</pre>
<h4> ビュー</h4>
<pre class="brush: php;">
&lt;?php echo $this-&gt;form; ?&gt;
</pre>
<h4> 出力</h4>
<pre class="brush: xml;">
&lt;form enctype=&quot;application/x-www-form-urlencoded&quot; action=&quot;/admin/index/register/&quot; method=&quot;post&quot;&gt;
&lt;dl class=&quot;zend_form&quot;&gt;
&lt;/dl&gt;
&lt;/form&gt;
</pre>
<h3>■ 要素を作る</h3>
<p>簡単。（コントローラ）</p>
<pre class="brush: php;">
$name = $form-&gt;createElement('text', 'name');
</pre>
<p>addElement がもっと簡単（コントローラ）</p>
<pre class="brush: php;">
$form-&gt;addElement('text', 'name');
</pre>
<p>バリデートもフィルタリングも一緒に追加できちゃう。（コントローラ）</p>
<pre class="brush: php;">
$form-&gt;addElement(
    'text',
    'name',
    array(
        'validators' =&gt; array(
            array('Regex', false, array('/^[a-z]/i'))
        ),
        'label'      =&gt; 'Name : ',
        'required'   =&gt; true,
        'filters'    =&gt; array(
            'StringToLower',
            'StripTags'
        )
    )
);
</pre>
<p>こんなんもある。めんどー。（コントローラ）</p>
<pre class="brush: php;">
require_once 'Zend/Form/Element/Text.php';
$name = new Zend_Form_Element_Text('name');
</pre>
<h3>■ バリデータを作る</h3>
<pre class="brush: php;">
addValidator(mixed $nameOrValidator, bool $breakChainOnFailure, array $options)
</pre>
<pre class="brush: php;">
$name = new Zend_Form_Element_Text('name');
$name-&gt;addValidator('Alnum', false, array(true))
    -&gt;addValidator('Regex', false, array('/^[a-zA-Z\s]+/'))
    -&gt;setLabel('Name : ')
    -&gt;setRequired(true);
</pre>
<dl>
<dt>Zend_Form_Element::addValidator(string $class, bool $is_next, array $options);</dt>
<dd>第一引数で指定したバリデータを要素に付加する。</dd>
</dl>
<h4> バリデータ一覧</h4>
<p><a href="http://framework.zend.com/manual/ja/zend.validate.set.html">http://framework.zend.com/manual/ja/zend.validate.set.html</a></p>
<h3>■フィルターを作る</h3>
<pre class="brush: php;">
addFilter(mixed $nameOrFilter, array $options)
</pre>
<pre class="brush: php;">
$name = new Zend_Form_Element_Text('name');
$name-&gt;addFilter('StringToLower');
</pre>
<h4> フィルタ一覧</h4>
<p><a href="http://zendframework.com/manual/1.5/ja/zend.filter.set.html">http://zendframework.com/manual/1.5/ja/zend.filter.set.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/07/21/zend_form%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Viewをもっと触ってみる</title>
		<link>http://blog.justoneplanet.info/2010/07/21/zend_view%e3%82%92%e3%82%82%e3%81%a3%e3%81%a8%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/07/21/zend_view%e3%82%92%e3%82%82%e3%81%a3%e3%81%a8%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 16:31:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2740</guid>
		<description><![CDATA[■パーシャルビュー scripts配下から指定する。 &#60;?php echo $this-&#62;partial('index/edit.phtml'); ?&#62; 他のビュースクリプトを呼び出すための仕組みだ。  [...]]]></description>
			<content:encoded><![CDATA[<h3>■パーシャルビュー</h3>
<p>scripts配下から指定する。</p>
<pre class="brush: php;">
&lt;?php echo $this-&gt;partial('index/edit.phtml'); ?&gt;
</pre>
<p>他のビュースクリプトを呼び出すための仕組みだ。</p>
<pre class="brush: php;">
&lt;?php
echo $this-&gt;partial(
    'index/edit.phtml',
    array(
        'val' =&gt; $this-&gt;val
    )
);
?&gt;
</pre>
<p>上述のように、変数は明示的して引数で渡す必要がある。</p>
<h3>■プレイスホルダ</h3>
<h4>コントローラ</h4>
<pre class="brush: php;">
$this-&gt;view-&gt;HeadScript()-&gt;appendFile('/admin/js/init.js');
</pre>
<h4>ビュー</h4>
<pre class="brush: php;">
&lt;?php echo $this-&gt;HeadScript(); ?&gt;
</pre>
<h4>出力</h4>
<pre class="brush: xml;">
&lt;script type=&quot;text/javascript&quot; src=&quot;/admin/js/init.js&quot;&gt;&lt;/script&gt;
</pre>
<h3>■Zend_Translate</h3>
<p>その名の通り多言語サイトをつくるときに使うやつ。</p>
<pre class="brush: php;">
Zend_Registry::set(
    'Zend_Translate',
    new Zend_Translate(
        'array',
        array(
            'submit' =&gt; '送信'
        ),
        'ja'
    )
);
</pre>
<h4>ビュー</h4>
<pre class="brush: php;">
&lt;?php echo $this-&gt;formSubmit('', $this-&gt;translate('submit')); ?&gt;
</pre>
<h4>出力</h4>
<pre class="brush: xml;">
&lt;input type=&quot;submit&quot; name=&quot;&quot; id=&quot;&quot; value=&quot;送信&quot;&gt;
</pre>
<p>なんかファイルフォーマットのアダプタが<a href="http://zendframework.com/manual/ja/zend.translate.adapter.html">いっぱい</a>ある。</p>
<h3>■自作ビューヘルパー</h3>
<h4>クラスを定義</h4>
<p>application/modules/admin/views/helpers/Br.php</p>
<pre class="brush: php;">
&lt;?php
class Zend_View_Helper_Br
{
    //呼び出し元のZend_Viewが自動的に$viewに代入される
    public $view;
    public function setView(Zend_View_Interface $view)
    {
        $this-&gt;view = $view;
    }
    public function br()
    {
        return &quot;&lt;br /&gt;\n&quot;;
    }
}
?&gt;
</pre>
<h4>コントローラ</h4>
<pre class="brush: php;">
$this-&gt;view-&gt;addHelperPath('application/modules/admin/views/helpers', 'Zend_View_Helper_');
</pre>
<h4>ビュー</h4>
<pre class="brush: php;">
&lt;?php echo $this-&gt;br(); ?&gt;
</pre>
<p>どっちかというと命名規則が重要である。</p>
<dl>
<dt>自作クラス名</dt>
<dd>Zend_View_Helper_ + Br</dd>
<dt>自作クラス名(メソッド)</dt>
<dd>br</dd>
<dt>ビュー</dt>
<dd>echo $this-&gt;br();</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/07/21/zend_view%e3%82%92%e3%82%82%e3%81%a3%e3%81%a8%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Viewを触ってみる</title>
		<link>http://blog.justoneplanet.info/2010/07/19/zend_view%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/07/19/zend_view%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 09:13:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2725</guid>
		<description><![CDATA[$this->_viewで色々設定できるらしー。 ■パスの指定 class IndexController extends Zend_Controller_Action { public function init()  [...]]]></description>
			<content:encoded><![CDATA[<p>$this->_viewで色々設定できるらしー。</p>
<h3>■パスの指定</h3>
<pre class="brush: php;">
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        $this-&gt;_session    = new Zend_Session_Namespace('global');
        $this-&gt;view-&gt;module     = $this-&gt;_getParam('module');
        $this-&gt;view-&gt;controller = $this-&gt;_getParam('controller');
        $this-&gt;view-&gt;action     = $this-&gt;_getParam('action');
    }

    public function indexAction()
    {
        // view 関連のディレクトリのパス（helpers,filters,scriptsが含まれる）
        $this-&gt;view-&gt;setBasePath('../views');
        // filters関連のディレクトリのパス
        $this-&gt;view-&gt;setFilterPath('../views/filters');
        // helpers関連のディレクトリのパス
        $this-&gt;view-&gt;setHelperPath('../views/helpers');
        // scripts関連のディレクトリのパス
        $this-&gt;view-&gt;setScriptPath('../views/scripts');
        // view 関連のディレクトリのパス（helpers,filters,scriptsが含まれる）
        $this-&gt;view-&gt;addBasePath('../views');
        // filters関連のディレクトリのパス
        $this-&gt;view-&gt;addFilterPath('../views/filters');
        // helpers関連のディレクトリのパス
        $this-&gt;view-&gt;addHelperPath('../views/helpers');
        // scripts関連のディレクトリのパス
        $this-&gt;view-&gt;addScriptPath('../views/scripts');
        $this-&gt;view-&gt;title = 'ページのタイトル';
    }
}
</pre>
<h3>■エンコードとエスケープ</h3>
<p>ガラパゴス携帯だからsjisとか。</p>
<pre class="brush: php;">
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        $this-&gt;_session    = new Zend_Session_Namespace('global');
        $this-&gt;view-&gt;module     = $this-&gt;_getParam('module');
        $this-&gt;view-&gt;controller = $this-&gt;_getParam('controller');
        $this-&gt;view-&gt;action     = $this-&gt;_getParam('action');
    }

    public function indexAction()
    {
        $this-&gt;view-&gt;encoding('Shift_JIS');// 文字コードを指定
        $this-&gt;view-&gt;escape('htmlentities');// escapeで使う関数を指定
        $this-&gt;view-&gt;title = 'ページのタイトル';
    }
}
</pre>
<h3>■フィルタ</h3>
<pre class="brush: php;">
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        $this-&gt;_session    = new Zend_Session_Namespace('global');
        $this-&gt;view-&gt;module     = $this-&gt;_getParam('module');
        $this-&gt;view-&gt;controller = $this-&gt;_getParam('controller');
        $this-&gt;view-&gt;action     = $this-&gt;_getParam('action');
    }

    public function indexAction()
    {
        $this-&gt;view-&gt;setFilter('hogeFilter');
        $this-&gt;view-&gt;title = 'ページのタイトル';
    }
}
</pre>
<p>views/filters配下に設置。</p>
<pre class="brush: php;">
class Zend_Filter_HogeFilter extends Zend_Filter
{
    public function filter($value)
    {
        $value = preg_replace('/&lt;p&gt;/', '&lt;p&gt;&lt;i&gt;', $value);
        return $value;
    }
}
</pre>
<h3>■ヘルパー</h3>
<p>よく使われる要素のビューヘルパはZend Frameworkで標準的に準備されてるらしー。</p>
<h4>フォーム</h4>
<p>第三引数でフォームの内容を指定できる。falseを指定すると開始タグしか出力されない。</p>
<pre class="brush: php;">
&lt;?php
echo $this-&gt;form(
    'form',
    array(
        'action' =&gt; '/index/register',
        'method' =&gt; 'post'
    ),
    $this-&gt;formText('dateTime', '', array('size' =&gt; '30')) .
    $this-&gt;formSubmit('', $this-&gt;translate('submit'))
);
?&gt;
</pre>
<h4>URL</h4>
<p>有用性が良く分からん。</p>
<pre class="brush: php;">
&lt;?php
echo $this-&gt;url(array(
    'controller' =&gt; 'Index',
    'action'     =&gt; 'index'
));
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/07/19/zend_view%e3%82%92%e8%a7%a6%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Frameworkでテーブルを左結合する</title>
		<link>http://blog.justoneplanet.info/2010/06/06/zend-framework%e3%81%a7%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%82%92%e5%b7%a6%e7%b5%90%e5%90%88%e3%81%99%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/06/06/zend-framework%e3%81%a7%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%82%92%e5%b7%a6%e7%b5%90%e5%90%88%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 18:51:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2590</guid>
		<description><![CDATA[$select-&#62;joinLeft( 'child', &#34;parent.`id` = child.`id_parent`&#34;, array( 'id', 'column' ) ); 以上。]]></description>
			<content:encoded><![CDATA[<pre class="brush: php;">
$select-&gt;joinLeft(
    'child',
    &quot;parent.`id` = child.`id_parent`&quot;,
    array(
        'id',
        'column'
    )
);
</pre>
<p>以上。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/06/06/zend-framework%e3%81%a7%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%82%92%e5%b7%a6%e7%b5%90%e5%90%88%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Controller_Router_Route_Regexで正規表現によるルーティング設定を行う</title>
		<link>http://blog.justoneplanet.info/2010/02/22/zend_controller_router_route_regex%e3%81%a7%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be%e3%81%ab%e3%82%88%e3%82%8b%e3%83%ab%e3%83%bc%e3%83%86%e3%82%a3%e3%83%b3%e3%82%b0%e8%a8%ad%e5%ae%9a%e3%82%92%e8%a1%8c/</link>
		<comments>http://blog.justoneplanet.info/2010/02/22/zend_controller_router_route_regex%e3%81%a7%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be%e3%81%ab%e3%82%88%e3%82%8b%e3%83%ab%e3%83%bc%e3%83%86%e3%82%a3%e3%83%b3%e3%82%b0%e8%a8%ad%e5%ae%9a%e3%82%92%e8%a1%8c/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 16:35:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2420</guid>
		<description><![CDATA[以下のように、Zend_Controller_Router_Route_Regexを使用する。 $front-&#62;getRouter()-&#62;addRoute( 'page', new Zend_Controll [...]]]></description>
			<content:encoded><![CDATA[<p>以下のように、Zend_Controller_Router_Route_Regexを使用する。</p>
<pre class="brush: php;">
$front-&gt;getRouter()-&gt;addRoute(
	'page',
	new Zend_Controller_Router_Route_Regex(
		'page_(\d+)\.html',
		array(
			'controller' =&gt; 'Index',
			'action'     =&gt; 'page'
		),
		array(
			1 =&gt; 'pageid'
		)
	)
);
</pre>
<p>Actionからは以下のコードでマッチした部分を参照できる。</p>
<pre class="brush: php;">
$this-&gt;_getParam('pageid');
</pre>
<p>但し、URLヘルパーやこのクラスのメソッドを使用する場合は第4引数が必要となる。</p>
<pre class="brush: php;">
$front-&gt;getRouter()-&gt;addRoute(
	'page',
	new Zend_Controller_Router_Route_Regex(
		'page_(\d+)\.html',
		array(
			'controller' =&gt; 'Index',
			'action'     =&gt; 'page'
		),
		array(
			1 =&gt; 'pageid'
		),
		'page_%d.html'
	)
);
</pre>
<h4>参考</h4>
<ul>
<li>http://framework.zend.com/manual/ja/zend.controller.router.html</li>
<li>http://codezine.jp/article/detail/2226?p=2</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/02/22/zend_controller_router_route_regex%e3%81%a7%e6%ad%a3%e8%a6%8f%e8%a1%a8%e7%8f%be%e3%81%ab%e3%82%88%e3%82%8b%e3%83%ab%e3%83%bc%e3%83%86%e3%82%a3%e3%83%b3%e3%82%b0%e8%a8%ad%e5%ae%9a%e3%82%92%e8%a1%8c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendFrameworkでコマンドラインからアクションを実行する</title>
		<link>http://blog.justoneplanet.info/2010/02/14/zendframework%e3%81%a7%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%83%a9%e3%82%a4%e3%83%b3%e3%81%8b%e3%82%89%e3%82%a2%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%99%e3%82%8b/</link>
		<comments>http://blog.justoneplanet.info/2010/02/14/zendframework%e3%81%a7%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%83%a9%e3%82%a4%e3%83%b3%e3%81%8b%e3%82%89%e3%82%a2%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 14:56:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2394</guid>
		<description><![CDATA[コマンドラインにおけるオプションの設定・取得。&#124;の後がエイリアス名、=の後の文字列で型を指定できる。 try { $options = new Zend_Console_Getopt( array( 'help&#124;h' = [...]]]></description>
			<content:encoded><![CDATA[<p>コマンドラインにおけるオプションの設定・取得。|の後がエイリアス名、=の後の文字列で型を指定できる。</p>
<pre class="brush: php;">
try {
    $options = new Zend_Console_Getopt(
        array(
            'help|h'        =&gt; 'help.',
            'zfm|m=s'       =&gt; 'module',
            'zfc|c=s'       =&gt; 'controller',
            'zfa|a=s'       =&gt; 'action'
        )
    );
    $options-&gt;parse();
}
catch(Zend_Console_Getopt_Exception $e){
    die($e-&gt;getMessage() . ' : ' . $e-&gt;getUsageMessage());
}
</pre>
<p>Zend_Controller_Request_Simpleがポイント。アクション、コントローラ、モジュールを引数に指定してリクエストオブジェクトを取得する。</p>
<pre class="brush: php;">
if(isset($options-&gt;zfa) &amp;&amp; isset($options-&gt;zfc) &amp;&amp; isset($options-&gt;zfm)){
    $request = new Zend_Controller_Request_Simple(
        $options-&gt;zfa,
        $options-&gt;zfc,
        $options-&gt;zfm
    );
    $front = Zend_Controller_Front::getInstance();
    $front-&gt;setRequest($request);
    $front-&gt;setRouter(new Custom_Controller_Router_Cli());
    $front-&gt;setResponse(new Zend_Controller_Response_Cli());
    $front-&gt;throwExceptions(true);
    $front-&gt;addModuleDirectory(dirname(__FILE__) . '/application/modules');
    $front-&gt;dispatch();
}
</pre>
<p>Custom_Controller_Router_Cliはこんな感じ。</p>
<pre class="brush: php;">
&lt;?php
require_once 'Zend/Controller/Router/Interface.php';
require_once 'Zend/Controller/Router/Abstract.php';

class Custom_Controller_Router_Cli extends Zend_Controller_Router_Abstract implements Zend_Controller_Router_Interface
{
    public function assemble($userParams, $name = null, $reset = false, $encode = true) {}
    public function route(Zend_Controller_Request_Abstract $dispatcher) {}
}
</pre>
<p>基本的には以上で実行できるが</p>
<h3>■アクセスコントロールの設定</h3>
<p>アクセスコントロールを行っている場合は上述のコードよりも先にアクセスできるようにしなければならない。以下は一例。</p>
<pre class="brush: php;">
$sesion = new Zend_Session_Namespace('global');
$sesion-&gt;userLevel = 'admin';
$acl = new Zend_Acl();
$acl-&gt;addRole(new Zend_Acl_Role('guest'));
$acl-&gt;addRole(new Zend_Acl_Role('admin'), 'guest');
$acl-&gt;add(new Zend_Acl_Resource('guestPage'));
$acl-&gt;add(new Zend_Acl_Resource('adminPage'));
$acl-&gt;allow('guest');
$acl-&gt;allow('admin');
$acl-&gt;deny('guest', 'adminPage');
$acl-&gt;allow('admin', 'adminPage');
Zend_Registry::set('acl', $acl);
</pre>
<p>基本的には一般ユーザが閲覧（実行）できる場所に、このファイルを配置するのは良くない。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/02/14/zendframework%e3%81%a7%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%83%a9%e3%82%a4%e3%83%b3%e3%81%8b%e3%82%89%e3%82%a2%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e5%ae%9f%e8%a1%8c%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendFrameworkビュースクリプトでのbodyタグ</title>
		<link>http://blog.justoneplanet.info/2010/01/12/zendframework%e3%83%93%e3%83%a5%e3%83%bc%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%81%a7%e3%81%aebody%e3%82%bf%e3%82%b0/</link>
		<comments>http://blog.justoneplanet.info/2010/01/12/zendframework%e3%83%93%e3%83%a5%e3%83%bc%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%81%a7%e3%81%aebody%e3%82%bf%e3%82%b0/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:19:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2321</guid>
		<description><![CDATA[以下のように記述するとcssで装飾しやすい気がする。 ■コントローラ public function init(){ $this-&#62;_view-&#62;module = $this-&#62;_getParam('m [...]]]></description>
			<content:encoded><![CDATA[<p>以下のように記述するとcssで装飾しやすい気がする。</p>
<h3>■コントローラ</h3>
<pre class="brush: php;">
public function init(){
    $this-&gt;_view-&gt;module     = $this-&gt;_getParam('module');
    $this-&gt;_view-&gt;controller = $this-&gt;_getParam('controller');
    $this-&gt;_view-&gt;action     = $this-&gt;_getParam('action');
}
</pre>
<h3>■ビュー</h3>
<pre class="brush: php;">
&lt;body class=&quot;&lt;?php print($this-&gt;controller); ?&gt;&quot; id=&quot;&lt;?php print($this-&gt;controller); ?&gt;_&lt;?php print($this-&gt;action); ?&gt;&quot;&gt;
</pre>
<p>ちなみに以下のようになっている。</p>
<pre class="brush: php;">
print($this-&gt;module);//モジュール名
print($this-&gt;controller);//コントローラ名
print($this-&gt;action);//アクション名
</pre>
<h4>出力例</h4>
<pre class="brush: xml;">
&lt;body class=&quot;category&quot; id=&quot;category_register&quot;&gt;
</pre>
<div class="kakomi">
<h4>参考</h4>
<p>以下の例の場合を考えてみる。</p>
<pre class="brush: php;">
&lt;body class=&quot;&lt;?php print($this-&gt;module); ?&gt; &lt;?php print($this-&gt;controller); ?&gt; &lt;?php print($this-&gt;action); ?&gt;&quot;&gt;
</pre>
<h5>出力例</h5>
<pre class="brush: xml;">
&lt;body class=&quot;category&quot; id=&quot;category_register&quot;&gt;
</pre>
<p>一見素晴らしいが、IEが以下のセレクタに対応していないため使用できない。</p>
<pre class="brush: css;">
body.admin.category.register {
	background-color: red;
}
body.register {
	background-color: blue;
}
</pre>
<p>上述のように記述するとIE6のみbodyの背景色がblueになるはずだ。</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/01/12/zendframework%e3%83%93%e3%83%a5%e3%83%bc%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%81%a7%e3%81%aebody%e3%82%bf%e3%82%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Exceptionのメソッド</title>
		<link>http://blog.justoneplanet.info/2010/01/10/zend_exception%e3%81%ae%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89/</link>
		<comments>http://blog.justoneplanet.info/2010/01/10/zend_exception%e3%81%ae%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 18:48:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=2304</guid>
		<description><![CDATA[以下の通り。 array(10) { [0] =&#62; &#38;object(ReflectionMethod)#54 (2) { [&#34;name&#34;] =&#62; string(7) &#34;_ [...]]]></description>
			<content:encoded><![CDATA[<p>以下の通り。</p>
<pre class="brush: php;">
array(10) {
  [0] =&gt; &amp;object(ReflectionMethod)#54 (2) {
    [&quot;name&quot;] =&gt; string(7) &quot;__clone&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [1] =&gt; &amp;object(ReflectionMethod)#55 (2) {
    [&quot;name&quot;] =&gt; string(11) &quot;__construct&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [2] =&gt; &amp;object(ReflectionMethod)#56 (2) {
    [&quot;name&quot;] =&gt; string(10) &quot;getMessage&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [3] =&gt; &amp;object(ReflectionMethod)#57 (2) {
    [&quot;name&quot;] =&gt; string(7) &quot;getCode&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [4] =&gt; &amp;object(ReflectionMethod)#58 (2) {
    [&quot;name&quot;] =&gt; string(7) &quot;getFile&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [5] =&gt; &amp;object(ReflectionMethod)#59 (2) {
    [&quot;name&quot;] =&gt; string(7) &quot;getLine&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [6] =&gt; &amp;object(ReflectionMethod)#60 (2) {
    [&quot;name&quot;] =&gt; string(8) &quot;getTrace&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [7] =&gt; &amp;object(ReflectionMethod)#61 (2) {
    [&quot;name&quot;] =&gt; string(11) &quot;getPrevious&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [8] =&gt; &amp;object(ReflectionMethod)#62 (2) {
    [&quot;name&quot;] =&gt; string(16) &quot;getTraceAsString&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
  [9] =&gt; &amp;object(ReflectionMethod)#63 (2) {
    [&quot;name&quot;] =&gt; string(10) &quot;__toString&quot;
    [&quot;class&quot;] =&gt; string(9) &quot;Exception&quot;
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2010/01/10/zend_exception%e3%81%ae%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendFramework Zend_Uri</title>
		<link>http://blog.justoneplanet.info/2009/09/28/zendframework-zend_uri/</link>
		<comments>http://blog.justoneplanet.info/2009/09/28/zendframework-zend_uri/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 13:52:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ZendFramework]]></category>

		<guid isPermaLink="false">http://blog.justoneplanet.info/?p=1999</guid>
		<description><![CDATA[以下のようにすると文字列がURIとして妥当かどうか検証できる。 &#60;?php require_once 'Zend/Uri.php'; $uri = 'http://example.org'; if(Zend_Uri [...]]]></description>
			<content:encoded><![CDATA[<p>以下のようにすると文字列がURIとして妥当かどうか検証できる。</p>
<pre class="brush: php;">
&lt;?php
require_once 'Zend/Uri.php';

$uri = 'http://example.org';
if(Zend_Uri::check($uri)){
    //this is valid as a uri
}
else{
    //this is not valid as a uri
}
</pre>
<div class="kakomi">
<h4>各メソッドについて</h4>
<dl>
<dt>bool Zend_Uri::check(string $url)</dt>
<dd>与えられた文字列がURIとして適当か判定する。</dd>
</dl>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.justoneplanet.info/2009/09/28/zendframework-zend_uri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

