如何在Codeigniter中加载控制器?

时间:2015-02-16 00:26:12

标签: php css codeigniter

控制器未加载页面。我尝试解决此问题,但我仍然收到错误 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>

我的问题是我无法打开页面 我应该添加什么? meybe我的代码有问题。
在任何帮助下我都非常感激,谢谢

1 个答案:

答案 0 :(得分:0)

在你的控制器上,你需要一个索引作为基础,这就是它没有拿起页面的原因。然后一旦完成

路线$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');
}   
}