2017-09-27 56 views
0

我是新來的代碼點火器框架。我有問題從控制器調用視圖。無法從phph中的控制器加載視圖 - codeigniter

我在我的應用程序/控制器/文件夾3個三個控制器中我的意見/模板/文件夾 employee.phphome.phpdashboard.php

和5次 header.phpfooter.phpsidebar.phptemplate.phptopmenu.php

並在我的主要意見文件夾3意見 addEmployee.php,home.phpdashboard.php

我能夠擊中家庭和儀表板控制器,但無法命中員工控制器加載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.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/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沒有。

我也曾嘗試這些URL,但沒有運氣

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

任何想法,什麼是錯的這個addEmployee看法?或任何鏈接?

+0

https://www.codeigniter.com/user_guide/general/views.html#loading-multiple -views – user4419336

回答

1

似乎你可能會使用錯誤的網址。要訪問,使 「addEmployee」 中的 「main_content」 的頁面嘗試

http://localhost:8050/test/employee 

該網址將運行Employee::index()

+0

找不到對象! 在此服務器上找不到請求的URL。如果您手動輸入網址,請檢查拼寫並重試。 如果您認爲這是服務器錯誤,請與網站管理員聯繫。 –

+0

這是在使用你的URL後 –

+0

它的工作。 thnks –

相關問題