控制器未加载页面。我试图解决此问题,但是仍然出现错误404 Page Not Found。这是我的代码:

config.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = 'http://localhost/latihan/CI/2_membuat_form/';
$config['index_page'] = 'index.php';
?>



route.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'siswa';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
?>



siswa.php(在文件夹控制器处)

<?php
class siswa
extends CI_Controller{

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

    function tambah_siswa(){
        $this->load->helper('form');
        $this->load->view('form_tambah_siswa');
    }
}
?>



form_tambah_siswa.php(在“文件夹”视图中)

<html>
    <head>
        <title>Form Registrasi DIMASEDU INSTITUE </title>
        <style>
        .elegant-aero {
            margin-left:auto;
            margin-right:auto;

            max-width: 500px;
            background: #D2E9FF;
            padding: 20px 20px 20px 20px;
            font: 12px Arial, Helvetica, sans-serif;
            color: #666;
        }
        .elegant-aero h1 {
            font: 24px "Trebuchet MS", Arial, Helvetica, sans-serif;
            padding: 10px 10px 10px 20px;
            display: block;
            background: #C0E1FF;
            border-bottom: 1px solid #B8DDFF;
            margin: -20px -20px 15px;
        }
        .elegant-aero h1>span {
            display: block;
            font-size: 11px;
        }

        .elegant-aero label>span {
            float: left;
            margin-top: 10px;
            color: #5E5E5E;
        }
        .elegant-aero label {
            display: block;
            margin: 0px 0px 5px;
        }
        .elegant-aero label>span {
            float: left;
            width: 20%;
            text-align: right;
            padding-right: 15px;
            margin-top: 10px;
            font-weight: bold;
        }
        .elegant-aero input[type="text"], .elegant-aero input[type="email"], .elegant-aero textarea, .elegant-aero select {
            color: #888;
            width: 70%;
            padding: 0px 0px 0px 5px;
            border: 1px solid #C5E2FF;
            background: #FBFBFB;
            outline: 0;
            -webkit-box-shadow:inset 0px 1px 6px #ECF3F5;
            box-shadow: inset 0px 1px 6px #ECF3F5;
            font: 200 12px/25px Arial, Helvetica, sans-serif;
            height: 30px;
            line-height:15px;
            margin: 2px 6px 16px 0px;
        }
        .elegant-aero textarea{
            height:100px;
            padding: 5px 0px 0px 5px;
            width: 70%;
        }
        .elegant-aero select {
            background: #fbfbfb url('down-arrow.png') no-repeat right;
            background: #fbfbfb url('down-arrow.png') no-repeat right;
           appearance:none;
            -webkit-appearance:none;
           -moz-appearance: none;
            text-indent: 0.01px;
            text-overflow: '';
            width: 70%;
        }
        .elegant-aero .button{
            padding: 10px 30px 10px 30px;
            background: #66C1E4;
            border: none;
            color: #FFF;
            box-shadow: 1px 1px 1px #4C6E91;
            -webkit-box-shadow: 1px 1px 1px #4C6E91;
            -moz-box-shadow: 1px 1px 1px #4C6E91;
            text-shadow: 1px 1px 1px #5079A3;

        }
        .elegant-aero .button:hover{
            background: #3EB1DD;
        }
        </style>
    </head>
    <body>
        <?php
                     echo form_open('siswa/tambah_siswa',array('class' => 'elegant-aero'));
                ?>
                <h1>Tambah Siswa
                     <span>Isikan data berikut dengan benar.</span>
                </h1>
                <label>
                     <span>Nama Siswa :</span>
                     <?php
                        echo form_input(array('id' => 'name', 'name' => 'name', 'placeholder' => 'Nama Lengkap ...'));
                     ?>
                 </label>
                 <label>
                      <span>Alamat :</span>
                      <?php
                         echo form_textarea(array('id' => 'message', 'name' => 'message', 'placeholder' => 'Alamat . . .'));
                      ?>
                 </label>
                 <label>
                      <span>Jurusan :</span>
                      <?php
                         echo form_dropdown('selection', array('IPA' => 'Jurusan IPA', 'IPS' => 'Jurusan IPS'));
                      ?>
                 </label>
                 <label>
                      <span>&nbsp;</span>
                      <?php
                          echo form_input(array('type' => 'submit', 'class' => 'button', 'value' => 'Kirim'));
                      ?>
                 </label>
                      <?php
                         echo form_close();
                      ?>
    </body>
</html>


我的问题是我无法打开页面。
我应该添加什么?
我的代码有问题。
我非常感谢您的帮助,谢谢

最佳答案

在您的控制器上,您需要一个索引作为基础,这就是为什么它不占用页面的原因。然后一旦完成

在路线$route['default_controller'] = 'siswa';

如果在文件夹$route['default_controller'] = 'foldername/siswa';

http://www.codeigniter.com/userguide3/general/controllers.html

控制器/Siswa.php

<?php

class Siswa extends CI_Controller{

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

public function index() {
 $this->tambah_siswa();
}

function tambah_siswa(){
    $this->load->helper('form');
    $this->load->view('form_tambah_siswa');
}
}

关于php - 如何在Codeigniter中加载 Controller ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28532900/

10-09 23:00