简体   繁体   中英

Can't access to the page

I'm new to Codeignator. it show me an error like "404 Page not found" when i browse it. below is the code

Controller Code: Insert.php

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

class Insertion extends CI_Controller {


    public function Insert()
    {
        $this->load->view('Insert_view');
    }
}
?>

View Code: Insert_view.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>

</head>
<body>

<div id="container">
    <h1>Hello world!</h1>
</div>

</body>
</html>

If your url is something like www.mywebsite.com/insertion than your controller file should be Insertion.php with class Insertion

If you like to use www.mywebsite.com/insert then your controller file should be Insert.php with class Insert and change the Insert function to index

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

 class Insertion extends CI_Controller {

   public function index(){
     $this->load->view('insert_view');   
   }

 }

?>

First View File Code Named ( Insertion_view.php )

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
</head>
<body>
<div id="container">
    <h1>Hello world!</h1>
</div>
</body>
</html>

Then the Controller File Code Named ( Welcome.php )

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

class Welcome extends CI_Model{
public function Insert()
    {
        $this->load->view('Insertion_view');
    }

Now write this URL in Browser http://127.0.0.1/Welcome/insert

Here insert is the method call from Welcome.php and show Insertion_view.php

You will get **


Hello World!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM