2013-07-31 60 views
2

大家好即時通訊新的PHP框架開發的一切,我不能讓這個代碼運行,請幫助我即時通訊使用XAMPPcodeigniter找不到對象! 404錯誤

我的歡迎控制器

<?php 

class Welcome extends CI_Controller 
{ 

public function index() 
{ 

    $this->load->view('home'); 

} 
} 

首頁查看

<html> 
<head> 
<title>CTS - home</title> 
<style type="text/css"> 
.auto-style1 { 
    text-align: center; 
} 
</style> 
</head> 

<body bgcolor="#C0C0C0" style="height: 226px"> 

<div class="auto-style1" style="height: 118px"> 
    <img alt="" height="126" src="<?php echo $this->config->item('base_url'); ? >/IMG/YUC.png" style="float: left" width="147"> 
    <center><h1 style="height: 39px; width: 696px">Cooperative Training Management  System</h1></center> 
</div> 
<br> 
<hr> 
<div class="auto-style1"> 
    <a href="<?php echo site_url('') ?>users/login"> 
    <img alt="YUC Employee" height="410" src="<?php echo $this->config- >item('base_url'); ?>/IMG/employee.png" width="139"> 
    </a> 
    <img alt="trainer" height="410" src="<?php echo $this->config->item('base_url'); ? >/IMG/Trainer.png" width="145"> 
    <a href="<?php echo site_url('') ?>users/login"> 
    <img alt="Student" height="410" src="<?php echo $this->config->item('base_url'); ? >/IMG/student.png" width="129"> 
    </a> 
    <h3>Employee&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp  ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Trainer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Student</h3> 
</div> 
<hr> 
<p align="right">Page generated in <strong>{elapsed_time}</strong> seconds</p> 
</body> 
</html> 

,這是第二控制器用戶

<?php 

class Users extends CI_Controller 
{ 

    function login() 
    { 
     $data['error']=0; 
     if($_POST){ 
      $this->load->model('user'); 
      $username=$this->input->post('username',ture); 
      $password=$this->input->post('password',true); 
      $user=$this->user->login($username,$password); 
      if(!$user){ 
       $data['error']=1; 
      }else{ 
       $this->session->set_userdata('userID',$user['userID']); 
       redirect(base_url().'home'); 
      } 
     } 
     $this->load->view('login'); 

    } 

    function logout() 
    { 
     $this->session->sess_destory(); 
     redirect(base_url().'home'); 
    } 
} 

這就是模型用戶

,這是登錄視圖

<html> 
<head> 
<title>CTS - Login</title> 
<style type="text/css"> 
.auto-style1 { 
    text-align: center; 
} 
</style> 
</head> 

<body bgcolor="#C0C0C0" style="height: 98px"> 

<div class="auto-style1" style="height: 118px"> 
    <img alt="" height="126" src="YUC.png" style="float: left" width="147"> 
    <center><h1 style="height: 113px; width: 696px">Cooperative Training Management  System</h1></center> 
</div> 
<br> 
<hr> 
<div class="auto-style1"> 

<fieldset name="Group1"> 
    <legend align="left"><h1>Login</h1></legend> 
    <?php if($error==1){ ?> 
    <p>Your Username/Password did not match.</p> 
    <? } ?> 
    <form action="<?=base_url()?>users/login" method="post" style="height: 96px"> 

     <label>Username </label><input name="Text1" type="text"> 
     <br> 
     <label>Password</label> <input name="Password1" type="password"> 
     <br><br> 
     <input name="Login" style="width: 96px" type="submit" value="Login"> 

    </form> 

</fieldset> 
</div> 
<hr> 
<p align="right">Page generated in <strong>{elapsed_time}</strong> seconds</p> 
</body> 
</html> 

htaccess的

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    #Removes access to the system folder by users. 
    #Additionally this will allow you to create a System.php controller, 
    #previously this would not have been possible. 
    #'system' can be replaced if you have renamed your system folder. 
    RewriteCond %{REQUEST_URI} ^system.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Submitted by: Fabdrol 
    #Rename 'application' to your applications folder name. 
    RewriteCond %{REQUEST_URI} ^application.* 
    RewriteRule ^(.*)$ /index.php?/$1 [L] 

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    # If we don't have mod_rewrite installed, all 404's 
    # can be sent to index.php, and everything works as normal. 
    # Submitted by: ElliotHaughin 

    ErrorDocument 404 /index.php 
</IfModule> 
+0

你究竟想要什麼?你有什麼嘗試?什麼不起作用? –

+0

,請複製粘貼完整的錯誤消息返回 – sbaaaang

+0

保持你的點精確貼在錯誤 –

回答

0

使用

base_url(); 

代替

$this->config->item('base_url'); 

,如果你想保持一個配置PARAM使用這樣的:

$this->config->config['base_url']; 

也這是不正常:

<?php echo site_url('') ?>users/login 

這樣使用它:

<?php echo site_url('users/login') ?> 

在結束檢查你是否有views/home.php檔案

不能看到任何其它錯誤代碼

然後確保您有:

$config['index_page'] = ''; 

,並使用此htaccess的:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L] 
+0

MMMM不和我一起工作我親愛的同樣的事情,我無法找到任何其他錯誤 – user2637286

+0

@ user2637286請發表您的完整的錯誤信息;未找到) – sbaaaang

+0

對象! 在此服務器上找不到請求的URL。推薦頁面上的鏈接似乎是錯誤或過時的。請通知該頁面的作者關於錯誤。 如果您認爲這是服務器錯誤,請與網站管理員聯繫。 錯誤404 本地主機 的Apache/2.4.4(Win32的)的OpenSSL/0.9.8y PHP/5.4.16 – user2637286

2

也許URL不正確。

http://localhost/projectfolder/index.php/controller/method 
在烏爾情況

http://localhost/yourprojectfolder/index.php/users/login 

替換 「projectfolder」, 「控制器」, 「方法」 與你的。確保爲用戶控制你的文件名是「users.php」

+0

謝謝親愛的工作 – user2637286

+0

沒問題:) –

0

如果你使用WAMP的服務器,然後打開「的httpd.conf」文件中,搜索
的LoadModule rewrite_module模塊/ mod_rewrite.so」,並刪除其中#在同一行的開始處.. 和
重啓WAMP服務器

然後將此代碼添加到您的.htaccess文件,該文件是在笨文件夾(如果該文件夾的根本不創建它)

RewriteEngine敘述上
的RewriteCond%{REQUEST_FILENAME}!-f
的RewriteCond%{REQUEST_FILENAME}!-d
重寫規則。*的index.php/$ 0 PT,L]

0

檢查其調用函數 爲如

Correct URL 
http://127.0.0.1/mysites/site1_ci_bootstrap/index.php/welcome/home 

可能是你的URL網址是

http://127.0.0.1/mysites/site1_ci_bootstrap/welcome/home 

注:最初總是需要提 「的index.php」 成重定向路徑到主要類「歡迎」,要刪除「index.php」把.htaccess腳本放入根文件夾,谷歌幾個htaccess腳本你找到一個。