0

say for instance i have the following method

    public function admin_edit($id = null)
{
    if(isset($_POST['name']))
    {
        $this->redirect('/Organizations/admin_index');
    }

   $this->set(array('org'=>$this->getModel('Organization')->find($id)));
   $this->setLayout('admin_layout');

}

Now i wish to call this function and set the $id variable = to 1

so in HTML i create the following link:

<a class="btn btn-info" href="/Organizations/admin_edit?id=1">Edit</a>

However this only creates a $_GET variable called id and sets it to 1

Is there a way to call functions where you set the parameter in the link?

2
  • 1
    $obj->admin_edit($_GET['id']); Commented Jun 3, 2014 at 11:40
  • Yeah i know i can do it in PHP afterwards but i am looking for a solution where you don't have to. The question is if it is possible Commented Jun 3, 2014 at 11:43

1 Answer 1

2

You will need some php logic to load the correct function, some kind of basic routing, as you can not directly call a function from a url (which is good, just think what a security nightmare that would be).

Something like this:

$func = isset($_GET['func']) ? $_GET['func'] : '';
$id = isset($_GET['id']) ? $_GET['id'] : 0;

switch($func){
    case 'func1':
         function_one($id);
         break;
    case 'func2':
         function_two($id);
         break;
    default:
         //handle incorrect
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.