Welcome Guest, Not a member yet? Register   Sign In
In Dropdown href not taking method in controller
#1

(This post was last modified: 02-08-2019, 10:00 AM by ciadmin.)

I have below code in view file - menu.php: (lines reduced for ease of checking..)
______________________________________________
<h3>ABC Fruits</h3>
<div id="Startup">

<ul class="" id="">
<li>Format
            <ul><li><a href="localhost:8015/citest3/index.php/soft1/sell">sell</a></li></ul>
            <ul><li><a href="localhost:8015/citest3/index.php/soft1/buy">buy</a></li></ul>
</li>

<li>Exit</li>
</ul>
__________________________________________________



And below Code in Controller - Soft1.php file:
___________________________________________________
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Soft1 extends CI_Controller {

public function index()
    {
       $this->load->view('menu');
    }
    
    public function sell()
        {
            echo "Sales Done";
        }
    
    public function buy()
        {
            echo "Purchase Done";
        }
    
}
___________________________________-

I get a menu as per attachment when I run the code. But when I click on menu option I expect the respective function (method) in the controller to run. (for eg: if I click on sell - the sell method in controller should run & "Sales Done" should get displayed). But it is not responding. But if I put "www.example.com" it goes there. Also, when I copy the "localhost:8015/citest3/index.php/soft1/buy" on browser it works! 

But it is not working when I click on the menu item.

What could be the problem? please suggest a solution.

Attached Files Thumbnail(s)
   
Reply
#2

You should be using CodeIgniter's base_url() it should have been setup in ./application/config/config.php
with an ending slash /.

The base_url should point to your document root or where your index.php file is.

You links would then look like this:

PHP Code:
<ul>
 
   <li>
 
       <a href="<?= base_url('soft1/sell');?>">sell</a>
 
   </li>
</
ul
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

You could also add "http://" to the beginning ot the href, to make sure it isn't treated as a relative URI.
You didn't say where your link does lead, just that it doesn't go to the right place.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB