Welcome Guest, Not a member yet? Register   Sign In
Get a variable from url
#1

[eluser]raduenea[/eluser]
I want to get a variable from url and to make a select in DB.

I have url like:
Code:
http://igniter.picturi-celebre.ro/picturi/abstracte/2
http://igniter.picturi-celebre.ro/picturi/munti/3
http://igniter.picturi-celebre.ro/picturi/oameni/4

The controller for picturi.php is:
Code:
class Picturi extends CI_Controller {


public function index()
{
  $data['title'] = "Picturi";
  $this->load->helper('url');
  $this->load->view('header', $data);
  $this->load->view('picturi/index');
  $this->load->view('footer');
}
}

If I access the link :http://igniter.picturi-celebre.ro/picturi , it's show me the content of the picturi.php views.
If I access the link: http://igniter.picturi-celebre.ro/picturi/abstracte/2, show:
Code:
404 Page Not Found

The page you requested was not found.

The variable "abstracte", "munti" etc, I need it in the url only for seo.

All I want is in picturi.php to get the variable the variable "2 , 3 or 4". Depends on ID I make a select in DB to show other results in picturi.php views.

In the classic way it's like you show many categories on a page and on click you show all the products from that category.

Thank you in advanced.
#2

[eluser]TheFuzzy0ne[/eluser]
When you access http://igniter.picturi-celebre.ro/picturi/abstracte/2, CodeIgniter is expects to find a method named "abstracte". Since you don't have this method defined, it's throws a 404 error.

To get around this, you can either set up a [url="http://ellislab.com/codeigniter/user-guide/general/routing.html"]route[/url] to redirect everything for the picturi controller through the index method, or you can use [url="http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping"]_remap()[/url] to pass all of your parameters to the index() method.
#3

[eluser]raduenea[/eluser]
It's working.
I add in routes.php the code:
Code:
$route['picturi/:any'] = 'picturi/item_lookup/$1';

In controller picturi.php I add a function:
Code:
public function item_lookup(){
  
  echo  $this->uri->segment(2, 'both'). '<br>';
  
}

If I acces the link: http://igniter.picturi-celebre.ro/picturi/abstracte/2 it's show "abstracte".

Thanks

#4

[eluser]raduenea[/eluser]
I open the link:
http://igniter.picturi-celebre.ro/picturi/abstracte/1

in Firefox and Chrome it's it's show me the correct answer: abstracte

In IE show's me: The webpage cannot be found.

Is there a problem with some Codeigniter functions in IE ?
#5

[eluser]raduenea[/eluser]
Nobody ?
#6

[eluser]TheFuzzy0ne[/eluser]
Hi, sorry about the delay. It seems that I'm the only one who wants to help people at the moment...

I assume you've fixed this problem? I just tried your link in IE9, and it works without any issues (apart from the PHP errors).
#7

[eluser]raduenea[/eluser]
Thank you for your response.
I did't do anything, now I see like you that is working. Smile

Very strange.




Theme © iAndrew 2016 - Forum software by © MyBB