Home > Software design >  My route somehow keep redirecting to wrong url
My route somehow keep redirecting to wrong url

Time:08-05

so i try make a pos(point of sale) program using ci3

im trying add a feature where admin can make new menu and submenu

but something went wrong when i goto controller "sistem"

my route show "sitename/sistem/sistem/menu" this route supposed to "sitename/sistem/menu". another controller also effected when i goto "dashboard" controller the route show "sistem/dashboard"

this is sistem controller

<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Sistem extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('M_menu');
        $this->load->model('M_user');
        if (!$this->session->userdata('email')) {
            redirect('auth');
        }
    }

    public function index()
    {
        $this->menu();
    }

    public function menu()
    {
        $data['judulpage'] = 'Manajemen Menu';
        $data['datamenu'] = $this->M_menu->getmenus()->result_array();
        $data['user'] = $this->M_user->getuserdata()->row_array();
        $this->form_validation->set_rules('menutambah', 'Menu', 'required');
        // $this->form_validation->set_message([
        //     'required' => 'Field menu add harus diisi'
        // ]);
        if ($this->form_validation->run() == false) {
            $this->load->view('template/header', $data);
            $this->load->view('template/sidebar', $data);
            $this->load->view('sistem/menu', $data);
            $this->load->view('template/footer');
        } else {
            $menu['menu'] = $this->input->post('menutambah');
            $this->M_menu->insertmenu($menu);
            $this->session->set_flashdata('flash','Sukses');
            redirect('sistem');
        }
    }

this is the sidebar.php i think this is the problem but i cant find the solution

    <?php
$role_id = $this->session->userdata('role_id');

$queryMenu = "SELECT `user_menu`.`id`, `menu`, `icon_menu`
                FROM `user_menu`
                JOIN `user_access_menu` ON `user_menu`.`id` = `user_access_menu`.`menu_id`
                WHERE `user_access_menu`.`role_id` = $role_id";
$menus = $this->db->query($queryMenu)->result_array();
                
?>
    <!-- BEGIN: Main Menu-->
    <div  data-scroll-to-active="true">
        <div >
            <ul  id="main-menu-navigation" data-menu="menu-navigation">
                <li ><span>MENU</span><i  data-toggle="tooltip" data-placement="right" data-original-title="Apps"></i>
                </li>
                <?php foreach($menus as $menu) : ?>
                    <?php 
                        $menuid = $menu['id'];
                        $querysubmenu = "SELECT * FROM `user_sub_menu` WHERE `menu_id` = $menuid AND `is_active` = 1";
                        $submenus = $this->db->query($querysubmenu)->result_array();
                    ?>
                <li ><a href="#"><i ></i><span ><?php echo strtoupper($menu['menu']); ?></span></a>
                <ul >
                    <?php foreach($submenus as $submenu) : ?>
                        <li>
                            <a  href="<?php echo $submenu['url']; ?>"><i ></i><span><?php echo $submenu['title']; ?></span></a>
                        </li>
                        <?php endforeach; ?>
                    </ul>
                </li>
                <?php endforeach; ?>
            </ul>
        </div>
    </div>

i take the url from database. u can see from inspect mode, the href redirecting to sistem/menu which is coorect url but when i click it, it goto sistem/sistem/menu

the problem the database

CodePudding user response:

fixed href="<?php echo base_url(); ?> i add / this before php tag but somehow it worked but still directing to wrong url localhost/sistem/menu it supposed to localhost/site/sistem/menu, so i add base_url to add my sitename and it work, thx

 <li>
    <a  href="<?php echo base_url(); ?><?php echo $submenu['url']; ?>">
<i ></i><span><?php echo $submenu['title']; ?></span></a>
                            </li>

CodePudding user response:

You do not need to call double <?php ?> tag.

just do this

<?php echo base_url($submenu['url']); ?>

or simplify the echo syntax with

<?= base_url($submenu['url']); ?>
  • Related