Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

php - Codeigniter4 Routing Failing

I have a problem with routing on my website as it's not working at all. At the beginning I wanted to have different Controllers for differetn tabs, but in the end I have changed that to view pages from the Home controller, but even that doesnt work.

Here is my Home controller - index and connection to Model works fine but the travel() function doesnt

    <?php 
namespace AppControllers;
use AppModelsHomeMod;
use CodeigniterController;

class Home extends BaseController {

    public function index() {
        $this->homeMod = new HomeMod();
        $data = array();
        $data['total'] = number_format($this->totalCases('total'));
    
    
        echo view('header');    
        echo view('welcome_message', $data);
        echo view('footer');
    }
    protected function totalCases(String $columnName) : String{
        $result = $this->homeMod->findColumn($columnName);
        return count($result) > 0 ? $result[0] : "0";
    } 


    public function travel() {
        return view('travel');
    }
    public function getPostCodeCases() {
        if(!IS_AJAX) return;
        var_dump("inside");
        die();
    } 
}

I cannot reach the getPostCodeCases() function either (the ajax call in js file works fine, its just not reaching this function).

And my routes file - as you can see i have tries with different variations

    $routes->get('/', 'Home::index');
 // $routes->get('/getPostCodeCases', 'Home::getPostCodeCases');
    $routes->post('/getPostCodeCases', 'Home::getPostCodeCases');
    $routes->match(['get', 'post'],'/getPostCodeCases',    'Home::getPostCodeCases');
    $routes->get("travel", "Travel::index");

 // $routes->add('/travel', 'Travel::index');
// $routes->add('travel', 'Home::travel');
// $routes->add('/travel/(:any)', 'Travel::index'); 

My base url: https://localhost/CI and $indexPage = '' (in App.php). I am sure I have missed something, somewhere but not sure where...

Could someone help me to resolve this problem ?

question from:https://stackoverflow.com/questions/65649061/codeigniter4-routing-failing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...