Welcome Guest, Not a member yet? Register   Sign In
Creating dynamic functions based on values from database
#2

[eluser]Pascal Kriete[/eluser]
I'm not sure I understand this correctly. You want segment 2 to be dynamic? Or you want segment 2 to define a new function? The latter isn't possible in php.

Option 1: Routing (docs)
Code:
$route = array(
                'default_controller'                    => 'main',
                'scaffolding_trigger'                    => '',

                'value1/(\w+)'    => 'value1/handle_dynamic/$1'
);
Option2: Remap (docs)
Code:
class Value1 extends Controller {

    /**
     * Constructor
     *
     * @access    public
     */
    function Value1()
    {
        parent::Controller();
    }

    // --------------------------------------------------------------------
    
    /**
     * Remap function calls
     *
     * @access    private
     */
    function _remap($func)
    {
        // Put already defined functions in here
        $allowed = array('test', 'test2');

        if (in_array($func, $allowed) )
        {
            $this->$func();
        }
        else
        {
            // Something to handle the second parameter
            $this->defined_function_to_handle_something($func);
        }
    }
}

Let me know if that answered your question at all Wink .

And welcome to CodeIgniter.


Messages In This Thread
Creating dynamic functions based on values from database - by El Forum - 10-05-2008, 01:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB