繁体   English   中英

无法从PHPh中的控制器加载视图-Codeigniter

[英]unable to load view from controller in phph - codeigniter

我是代码点火器框架的新手。 我在从控制器调用视图时遇到问题。

我的application / controllers /文件夹employee.phphome.phpdashboard.php有3个三个控制器

和5个视图在我的views / template /文件夹header.phpfooter.phpsidebar.phptemplate.phptopmenu.php

在我的主视图文件夹addEmployee.phphome.phpdashboard.php 3个视图

我能够点击家庭和仪表板控制器,但是无法点击雇员控制器来加载addEmployee视图。

这是我的addEmployee.php视图

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<title>Add Employee</title>
<div class="main-content">
        <?php include 'template/topmenu.php' ?>
        <!-- PAGE CODE STARTS BELOW FROM HERE -->
</div>

employee.php控制器

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

class Employee extends CI_Controller {

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

        $this -> load -> model('employee_model');

    }

    public function index() {
        $data['header'] = 'template/header';
        $data['sidebar'] = 'template/sidebar';
        $data['main_content'] = 'addEmployee';
        $data['footer'] = 'template/footer';
        $this->load->view('template/template',$data);
    }

    function functionToTestgetAndSaveEmployeeDetailsResult() {

        $result = $this -> getAndSaveEmployeeDetails();
        print_r($result);
    }
}
?>

template / template.php视图

<?php defined( 'BASEPATH') OR exit( 'No direct script access allowed'); ?>
<?php
    $this->load->view($header);
    $this->load->view($sidebar);
    $this->load->view($main_content);
    $this->load->view($footer);
?>

的.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

配置/ config.php文件

$config['base_url'] = 'http://localhost:8050/test/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

我正在使用此网址访问视图

http://localhost:8050/test/ for home
http://localhost:8050/test/dashbaord for dashbaord
http://localhost:8050/test/addEmployee for addEmployee

视图和仪表板视图由此工作,但addEmployee不起作用。

我也尝试过这些网址,但没有运气

http://localhost:8050/test/employee/addEmployee 
http://localhost:8050/test/index.php/addEmployee
http://localhost:8050/test/index.php/employee/addEmployee

任何想法,此addEmployee视图有什么问题? 或任何链接?

好像您使用的URL错误。 要访问使“ addEmployee”成为“ main_content”的页面,请尝试

http://localhost:8050/test/employee

该URL将运行Employee::index()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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