Maszgalang
Maszgalang

Reputation: 79

confused about codeigniter url route

I wanna ask about CI System, what should I do, if i have 1 controller the URL is:

http://localhost/apanel so that a controller Apanel I wanna make a 1 controller again and that effected in URL right ?

the new controller is users the url should be http://localhost/users what should i do if I want make the URL like this http://localhost/apanel/users

Upvotes: 1

Views: 66

Answers (4)

Saket
Saket

Reputation: 846

You should try this, WORKS FOR ME:

$route['apanel/'] = "apanel/<method(default-- index)>";
$route['apanel/user'] = "apanel/<user-method>";

in your application>config>routes.php.

Hope this helps. You can any type of routing here.

for example:

$route['apanel'] = "apanel";
$route['apanel/create'] = "apanel/create";
$route['apanel/(:any)/user/(:any)'] = "apanel/user/$1/$2";
$route['apanel/(:any)/about/(:any)'] = "apanel/about/$1/$2";

Upvotes: 1

Akbar Soft
Akbar Soft

Reputation: 1066

inside of apanel controllerClass use put this code...

public function users(){
  require('Users.php');//calling Users Contrller class..
  $test = new Users();
  $test->methodYouWant();//call what method you wanto call..
}

Upvotes: 0

Ashfaque Ali Solangi
Ashfaque Ali Solangi

Reputation: 1891

i think that should be so simple for you "Apanel" is a Controller and user is a function inside the Apanel Controller example :

class Apanel extends CI_Controller {
   public function index(){
     echo "you are at Apanel index function";
   }
   public function users(){
     echo "you are at users function";
   }
}

so URL

http://localhost/apanel

will give you output : (you are at Apanel index function) and

http://localhost/apanel/users

will give you output : (you are at users function)

Upvotes: 1

prakash tank
prakash tank

Reputation: 1267

It's actually simple . first go through some tutorial for CI.

In your case : http://localhost/apanel/users

Here apanel is your controller and users is the function under your apanel controller.

Reference : https://www.codeigniter.com/userguide3/general/urls.html

Upvotes: 0

Related Questions