Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
sample code tester
  • Hi, I used netbeans and xdebug, so not hard to debug my program, but I'm green for PHP and Fuelphp. So I made test program when I was not sure about methods and something around this. I know oil+console, but I won't use it. I'm GUI person. :D But also I don't want to make test program everytime... Then I made code tester. I don't know it useful for everyone, but good for beginner like me. ;) This code tester make a file on app/config, (keep code as config file), make sure change file name to avoid overwrite your and system configer files.
    <?php
    
    /*
     *  code tester by Hirohisa Kawase
     */
    
    class Controller_Codetester extends Controller {
        const CT_SAVE_GROUP = 'codetest'; // save file name, also config group
    
        function action_index() {
            // from here, output some tags to display characters correctly. 
            // When you output them in your class or use to extends Template class,
            // or just use only English, no needed.
            echo Html::doctype('html5');
            echo '<head><meta charset="UTF-8"></head><body>';
            // to here, output html tags
            Config::load(self::CT_SAVE_GROUP, true);
            $ct_code = '';
            $ct_codename = '';
            if (Input::get('load', false)) {
                $ct_code = Config::get(self::CT_SAVE_GROUP . '.' . Input::get('load'));
                $ct_codename = Input::get('load');
            }
            elseif (Input::post('code', false)) {
                $ct_code = Input::post('code');
            }
            $return_value = eval&#40;$ct_code&#41;;
            $ct_codename = $ct_codename != '' ? $ct_codename : (Input::post('codename', false) ? Input::post('codename') : '');
            if ($ct_codename != '') {
                if ($ct_code == '') {
                    Config::delete(self::CT_SAVE_GROUP . '.' . $ct_codename);
                }
                else {
                    Config::set(self::CT_SAVE_GROUP . '.' . $ct_codename, $ct_code);
                }
            }
            Config::save(self::CT_SAVE_GROUP, self::CT_SAVE_GROUP);
    
            echo Form::open(URI::current());
            echo Form::textarea('code', $ct_code, array('rows' => 20, 'cols' => 100));
            echo '<div>';
            echo Form::label('Code Name', 'codename');
            echo Form::input('codename', $ct_codename);
            echo Form::reset('reset', 'Reset');
            echo Form::submit('execute', 'Excute');
            echo '</div><div>';
            foreach (Config::get(self::CT_SAVE_GROUP) as $ct_key => $ct_value) {
                echo '<a href="' . Uri::current() . '?load=' . $ct_key . '">' . $ct_key . '</a> ';
            }
            echo '</div>';
            echo Form::close();
            // output tags from here.
            echo '</body>';
            // to here.
        }
    }
    

    Simple, it is just code tester, so keep it simple. ;) I save a test code, it is good see when I want to check functions...
    echo '<div>';
    echo 'Agent::browser() : ' . Agent::browser() . '<br />';
    echo 'Agent::platform() : ' . Agent::platform() . '<br />';
    echo 'Agent::charsets() : <br />';
    print_r(Agent::charsets());
    echo '</div><div>';
    echo 'Agent::version() : ' . Agent::version() . '<br />';
    echo 'Agent::properties() : <br />';
    print_r(Agent::properties());
    echo '<br />';
    echo '</div><div>';
    echo 'Input::uri() : ' . Input::uri() . '<br />';
    echo 'Input::method() : ' . Input::method() . '<br />';
    echo 'Input::protocol() : ' . Input::protocol() . '<br />';
    echo 'Input::ip() : ' . Input::ip() . '<br />';
    echo 'Input::real_ip() : ' . Input::real_ip() . '<br />';
    echo 'Input::server() : <br />';
    print_r(Input::server());
    echo '<br />';
    echo 'Input::referrer() : ' . Input::referrer() . '<br />';
    echo 'Input::user_agent() : ' . Input::user_agent() . '<br />';
    echo 'Input::all() : <br />';
    echo 'Input::all() make too many output, so turn it comment.';
    // print_r(Input::all());
    echo '<br />';
    echo 'Input::file&#40;&#41; : <br />';
    print_r(Input::file&#40;&#41;);
    echo '<br />';
    echo 'Input::param() : <br />';
    echo 'Input::param()  make too many output, so turn it comment.';
    // print_r(Input::param());
    echo '<br />';
    echo '</div><div>';
    echo 'Request::active()->parent() : ' . Request::active()->parent() . '<br />';
    echo 'Request::main()->children() : <br />';
    print_r(Request::main()->children());
    echo '<br />';
    echo 'Request::get_paths() I tried same code on document, but it became error... :D';
    // echo 'Request::get_paths() : ' . Request::get_paths() . '<br />';
    echo '</div><div>';
    echo 'URI::base() : ' . URI::base() . '<br />';
    echo 'URI::base(false) : ' . URI::base(false) . '<br />';
    echo 'URI::create() : ' . URI::create() . '<br />';
    echo "URI::create('codetest/index') : " . URI::create('codetest/index') . '<br />';
    echo 'URI::current() : ' . URI::current() . '<br />';
    echo 'URI::main() : ' . URI::main() . '<br />';
    echo 'URI::segment(1) : ' . URI::segment(1) . '<br />';
    echo 'URI::segment(2) : ' . URI::segment(2) . '<br />';
    echo 'URI::segments() : <br />';
    print_r(URI::segments());
    echo '</div><div =>';
    echo 'URI::to_assoc() : ' . URI::to_assoc() . '<br />';
    echo 'URI::string() : ' . URI::string() . '<br />';
    echo '</div>';
    

    And 'echo Debug::dump($this);' show good information to understand this framwork for beginner. (Specially, you are in trouble routing set.)
    ML Hirohisa Kawase

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!