• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Link

#1
[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

#2
[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-gui...llers.html
Remapping Function Calls

#3
[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?

#4
[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();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.