2006年10月23日

Model 練習與測試工具.

平常都要自己查一下Model 的回傳等等,常常會覺得挺麻煩的。

下面是自己寫的一個小工具,直接在畫面上填入要測試Model,然後輸入要 Run 的 Command ...
就可以了。
(目前無法做 save 的相關動作。)

Controller
程式碼:

<?php
class DemoController extends AppController
{
        //var $scaffold;
        var $name = 'Demo';
        var $uses = array();
        var $helpers = array('Html', 'Form' );

        function index(){
            if(!empty($this->data)){
                $command_str = '$model = new '.$this->data['Test']['model'].";\n";
                $command_str .= '$result = $model->'.$this->data['Test']['Command'].';';
                eval($command_str);
                $this->set('command_str',$command_str);
                $this->set('result',$result);
            }
        }
}
?>


View:
程式碼:

<form action="<?=$html->url('/demo/')?>" method="post">
    <label>Model Name</label>
    <?=$html->input('Test/model',array('size'=> '40'))?>
    <label>Function</label>
    <?=$html->input('Test/Command',array('size'=> '40'))?>
    <?=$html->submit();?>
</form>

<h1>Code</h1>
<?
if(isset($command_str)){
    highlight_string($command_str);
}
?>


<h1>Result</h1>
<?
if(isset($result)){
    pr($result);
}
?>

 

Posted by darkhero at 樂多Roodo! │16:05 │回應(0)引用(0)CakePHP
樂多分類:網路/3C 共同主題:PHP基本語法 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/2353100