Holy Coder
Holy Coder

Reputation: 31

Call direct function in codeigniter on baseurl

I am newbie to codeigniter.my problem is let suppose my baseurl is

www.xyz.com

Now I have function like this

class Front extends MY_Controller {

    public function index()
    {
        $this->__front_template('index');
    }
    public function about()
    {
        $this->__front_template('about-us');
    }

Now if I have to call about I call like

www.xyz.com/front/about

But I need to call like

www.xyz.com/about

How can I do that ?

Upvotes: 0

Views: 233

Answers (2)

Shahrukh Charlee
Shahrukh Charlee

Reputation: 52

You cannot call about directly as per your architecture, because of the following reason.

In CodeIgniter we have URL divided as: http://www.example.com/controller_name/function_name

If the function you are trying to call is index function that above can be written as: http://www.example.com/controller_name/

So, in order to call about directly you need to create a separate controller for it with the name about and you can write about code in index function. And your requirement will be fulfilled.

There are other complex ways to, but as you have mentioned you are newbie. so this will be best.

If you want a more efficient way, look at the documentation: https://www.codeigniter.com/userguide3/general/routing.html

Upvotes: 0

TarangP
TarangP

Reputation: 2738

You can use codeigniter URI routing

Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:

Codeigniter URL Work as

example.com/class/function/id/

So you must route for this type. in application/config/routes.php add code like

$route['about'] = 'Front/about';

it works .!

Upvotes: 1

Related Questions