How to provide link in codeigniter

this is my controller named Xyz_controller.php

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

    class Xyz_cntroller extends CI_Controller  
    {

public function __construct()
{
	parent:: __construct();

	$this->load->model("abc_model");
}


public function my_function($id)
{ 
	$data['mydata'] = $this->abc_model->somefunction($id);
	$this->load->view('myview',$data);
}

}

I am trying to do this by using this

 <a href="<?php echo site_url('Xyz_controller/my_function') ?>"><input typr="button">go</a> 

but its gicing error 404 even though myview is placed correctly in views folder ?
Am I doing this correctly ?
Please guide me

Are the typos in your live code, or just in the code you posted on here?

public function myf_function($id)
                  ^
<a href="<?php echo site_url('Xyz_controller/my_function') ?>"><input typr="button">go</a>
                                               ^                         ^

I don’t know Codeigniter, your function definition clearly shows it requires a parameter, but I can’t see where your link provides it. Does CI add that bit in for you somewhere?

3 Likes

hey thanks for reply I have corrected it its just my_function() .

Is this a new CodeIgniter installation and what is the version number?

Have you managed to get the Welcome Controller and welcome_message view to show?

CodeIgniter has a very good error logging system which you should investigate.

Have you set the Config Route to similar to the default route and welcome route?

https://www.codeigniter.com/user_guide/overview/appflow.html

https://www.codeigniter.com/user_guide/_images/appflowchart.gif

Please check the Controller Class name and the file Class name.

1 Like

Try adding declare(strict_types=1); to the top of your PHP files because it will *fail fast by displaying syntax errors, etc

<?php 
declare(strict_types=1); // ADD THIS LINE

defined('BASEPATH') OR exit('No direct script access allowed');

 class Xyz_cntroller extends CI_Controller  
 {

public function __construct()
{
  parent:: __construct();

  $this->load->model("abc_model");
}

public function my_function($id)
{ 
  $data['mydata'] = $this->abc_model->somefunction($id);
  $this->load->view('myview',$data);
}

}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.