![]() |
In Dropdown href not taking method in controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: In Dropdown href not taking method in controller (/showthread.php?tid=72760) |
In Dropdown href not taking method in controller - Sovani Shreeniwas - 02-08-2019 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. RE: In Dropdown href not taking method in controller - InsiteFX - 02-08-2019 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> RE: In Dropdown href not taking method in controller - ciadmin - 02-08-2019 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. |