Welcome Guest, Not a member yet? Register   Sign In
Need help with "segmenting" URI
#1

[eluser]ammtar[/eluser]
I know the Title sounds weird, but I don't know how to explain my issue within few words :-)

Anyway... I'm new with CI, please be gentle :-)

The company I work for (e.g. service.com) offers a service to our clients (client1, client2, client3,... , clinetN). The service is on our server and the have to go to http://service.com/client1, http:/service.com/client2 etc.

I made a controller homepage.php

Code:
class Homepage extends Controller {
  function index()
  {
    $this->load->view('homepage_view);
  }
}

in config/routes.php I have
Code:
$route['default_controller'] = "homepage";

If client goes to "his" page (http://service.com/client1) and to be able to see view file client_view.php (for all clients) I had to create
Code:
function client1 {
  $this->load->view('client_view);
}

within the homepahe.php controller.
The same for clinet2, client2,... Means, for EACH client same function but different name. And it could be hundreds of functions. And each time we got a new client I have to modify the homepahe.php controller. I know that's wrong and there is 110% better way - but I can't figure it out by myself.

Please, any suggestions?

p.s. I'm playing now with CI 1.7.3 because most of tutorials are for 1.7.x. Though, I plan to switch (once I'm comfortable) to CI 2.
#2

[eluser]ammtar[/eluser]
Forgot something...
I know it could be easily done by adding function in URI, like
http://service.com/clients/clinet1
and then "read" segment(2) and recognize the client, but our clients provide to their clients the URL of the service mostly over the phone and they WOULD REALLY LIKE (read: it must be that way) to have client name right after service.com.
#3

[eluser]ammtar[/eluser]
With
Code:
function _remap($method) {
  if (method_exists($this, $method)) {
    $this->$method($this->uri->segment(1));
  } else {
    $this->index($method);
}

the problem is fixed :-D

Though, http://service.com/homepage/client1 is ok. http://service.com/client1 is NOT.
"404 Page Not Found"

:-(
#4

[eluser]ammtar[/eluser]
What about re-routing
http://service.com/client1
to
http://service.com/foo/client1
?
#5

[eluser]John_Betong_002[/eluser]
I have something similar on a website:


1. fallthrough/last route is set to $route["(:any)"] = "homepage/get_client/$1";
2. class homepage->get_client() checks $this->uri->segment(3)
3. search database->table->clients
4. if valid client return with client's data else return NULL
5. class homepage->get_client()->result either view results or default search page

 
 
#6

[eluser]ammtar[/eluser]
GREAT! It works perfect...

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB