CodeIgniter Forums
Link - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Link (/showthread.php?tid=50933)



Link - El Forum - 04-13-2012

[eluser]prakash[/eluser]
Hi ,

I want an url to be like http://localhost/test/manageannexturetypes.html/delete/1

can anybody help me out in this scenario


Link - El Forum - 04-14-2012

[eluser]zay yar phone[/eluser]
Code:
// For URL request of http://localhost/test/manageannexturetypes.html/delete/1

class Test extends CI_Controller {


public function _remap($page,$params = array())
{

  // first element of the $params array() is the "delete"
  // second element is the 1

  $method = array_shift($params);

  switch ($page) {

  case 'manageannexturetypes.html':
   $method = method_exists($this,$method) ? $method : 'delete';
   break;

  case 'others.html':
   $method = method_exists($this,$method) ? $method : 'somethingelse';
   break;

  default:
   // default controller method
   $method = 'index';
  }

  return call_user_func_array(array($this,$method),$params);
}

public function delete($id = '')
{
  echo 'delete is called with the ID parameter of '. $id;
  // do your delete stuff here
}

public function index()
{
  echo 'index is called';
}
}

http://ellislab.com/codeigniter/user-guide/general/controllers.html
Remapping Function Calls


Link - El Forum - 04-15-2012

[eluser]prakash[/eluser]
Hi thanks for your reply .... i have another question so i need to call Test controller always? because i have same thing(http://localhost/test/manageannexturetypes.html/delete/1) for editing also and also manageannextureyears.html,.... so on so for every url i need to write switch case?


Link - El Forum - 04-16-2012

[eluser]zay yar phone[/eluser]
Yes.Another way to accomplish is that using associative array.
Code:
$options = array(
'manageannexturetypes.html' => 'manage_types',
'manageannextureyears.html' => 'manage_years',
'others.html' => 'if_any'
);

$page = (isset($options[$page])) ? $options[$page] : 'index'; // default is index
$this->$page();