简体   繁体   中英

HREF link is duplicating PHP

I'm having a problem with the link of my websites. I'm using CodeIgniter with PHP. I tried to access a page using a function by referring to it with href="controllers_name/function_name". But this happens.

This is the code of the href:

<li><a href="home/login">Dashboard</a></li>
<li><a href="home/customer">Customers</a></li>
<li><a href="home/order">Orders</a></li>
<li><a href="home/product">Products</a></li>
<li><a href="home/logout" ><b>Logout</b></a></li>

Here's the function call:

function customer()
{
    $this->load->view('customer_view');
}

function order()
{
    $this->load->view('order_view');
}

function product()
{
    $this->load->view('product_view');
}

function sales()
{
    $this->load->view('sale_view');
}

function inventory()
{
    $this->load->view('inventory_view');
}

function notes()
{
    $this->load->view('notes_view');
}

function service_offered()
{
    $this->load->view('service_offered_view');
}

function about_us()
{
    $this->load->view('about_us_view');
}

And when I try to click the other buttons, it doesn't work (the pages are separated just like the welcome page of CodeIgniter).

You have to use site_url() or base_url() for codeigniter to know what controller method to invoke. You're just doing href="home/login" , instead you have to do

href="<?= site_url('home/login') ?>"

So your html should look like the following

<li><a href="<?= site_url('home/login') ?>">Dashboard</a></li>
<li><a href="<?= site_url('home/customer') ?>">Customers</a></li>
<li><a href="<?= site_url('home/order') ?>">Orders</a></li>
<li><a href="<?= site_url('home/product') ?>">Products</a></li>
<li><a href="<?= site_url('home/logout') ?>"><b>Logout</b></a></li>

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM