CodeIgniter Forums
help with $_GET in CI - 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: help with $_GET in CI (/showthread.php?tid=56460)



help with $_GET in CI - El Forum - 12-20-2012

[eluser]look66[/eluser]
Hi I do not speak English, I am Brazilian, I speak English very bad.
My doubt is:

I was wondering if you can send the value of a variable after the first bar, example:

www.example.com.br/var1
www.example.com.br/var2

I wanted to send this variable for main page of the site, but the URL stay with this format

base url () + var

Anyone have any tips?
Thank you!


help with $_GET in CI - El Forum - 12-21-2012

[eluser]Rowan Wilson[/eluser]
check out the URI class: http://ellislab.com/codeigniter/user-guide/libraries/uri.html

I think that's what you are referring to.


help with $_GET in CI - El Forum - 12-21-2012

[eluser]look66[/eluser]
[quote author="rowstu" date="1356093092"]check out the URI class: http://ellislab.com/codeigniter/user-guide/libraries/uri.html

I think that's what you are referring to.[/quote]

Thanks for the reply

Currently I am passing the variable as follows:

http://www.example.com/Home/index/var1

I want the url to this view

http://www.example.com/var1

sending the 'var1' to the 'index' method of the controller 'Home'


help with $_GET in CI - El Forum - 12-21-2012

[eluser]PhilTem[/eluser]
I guess, routing is what you want to implement


help with $_GET in CI - El Forum - 12-21-2012

[eluser]InsiteFX[/eluser]
index method:
Code:
// --------------------------------------------------------------------

/**
  * index()
  *
  * index - default method called.
  *
  * @access public
  * @return void
  */
public function index($param = NULL)
{

}

Add this to your Controller:
Code:
// --------------------------------------------------------------------

/**
  * _remap()
  *
  * Remaps the URL segments.
  *
  * @access private
  * @param string
  * @param array
  * @return mixed
  */
public function _remap($method, $params = array())
{
  if (method_exists($this, $method))
  {
   return call_user_func_array(array($this, $method), $params);
  }

  show_404();
}

routes.php
Code:
// ------------------------------------------------------------------------
/**
* DO NOT! REMOVE THIS LINE
* This is for the _remap.
* ------------------------------------------------------------------------
*/
$route['(.*)'] = 'welcome/index/$1';

// ---------------- -== DO NOT REMOVE! the above line ==- -----------------



help with $_GET in CI - El Forum - 12-22-2012

[eluser]look66[/eluser]
@ InsiteFX thank you for your reply!
Your reply was exactly what I needed!

I only have one more doubt:
what function this 'if' you posted

[code]
if (method_exists ($ this, $ method))
{
return call_user_func_array (array ($ this, $ method), $ params);
}

show_404 ();
[/ code]


help with $_GET in CI - El Forum - 12-22-2012

[eluser]InsiteFX[/eluser]
CodeIgniter Users Guide - Controllers - Remapping Function Calls