Reputation: 20555
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?
Upvotes: 0
Views: 63
Reputation: 20469
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
}
Upvotes: 2