• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a URL segment and calling a function inside a Controller

#1
[eluser]Unknown[/eluser]
Hello gentlemen's. I'm new here and I started using CI a few days ago and I'm having a few troubles.

Sorry for my bad english and sorry if this thread is already in this forum. I've made a simple search and haven't solved my questions yet. Well, here we go!

What I want to do is to get a segment in my URL and call a function inside a Controller. So, in my case I have the URL: http://localhost/CI_Project_A/call/990

In my URL, the last number (990) will be the ID that I'll use to perform a search in my database. So, that last number is the call ID in my database. Ok, I've used $this->uri->segment and now I can pass that segment for a variable. That's not the problem.

But now, I wanna call a function to perform my search. Look what I've done until now: http://pastebin.com/xSAECRRf

And It's working for now, but when I access the URL http://localhost/CI_Project_A/call/990, I get a 404 Page Not Found, but I also get the text that I've performed in my DB.

I'm probably doing this wrong. If anyone here can help, I'll appreciate.
Thank's!

#2
[eluser]PhilTem[/eluser]
Maybe it will help you to look at

CI Routing
Controller _remap

and to know the basic procedural logic of CI:

Assume you have an URI, then the router will determine the controller. Then, CI checks there is a file named like your controller in ./application/controllers PLUS the class inside that file has the same name (this is possible after including the file). Furthermore, it will check if there is a _remap()-method in your controller. It is called if it exists. If there is no _remap()-function, CI will look for the "thing" you provided as the second URI-argument which is assumed to be a controller's method. If there is no method called like your second URI-argument, a 404 will be shown.

That means: You don't have a '990' method in your 'call' controller => there's a 404.

Solutions: Read the two links above and do either some routing or remapping.

Cheers and good luck!

#3
[eluser]johnpeace[/eluser]
Code:
http://localhost/CI_Project_A/

You should take a minute to learn about Apache virtualhosts...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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