2016-12-14 112 views
0

我有這個登錄功能:笨重定向不起作用

public function members() { 
    if($this->session->userdata('is_logged_in')){ 
    redirect('pag/index.php');  
}else{ 
    redirect('main/restricted'); 
} 

這將讓我一個404,如果我更迭登錄! 但是,如果我會嘗試這樣的:

public function members() { 
    if($this->session->userdata('is_logged_in')){ 
    $this->load->view('pag/index.php');  
}else{ 
    redirect('main/restricted'); 
} 

隨着$this->load->view它會工作,也是redirect('main/restricted')工作。我有redirect('pag/index.php');問題回到我404

THID是我.htaccess如何尋找:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /delta-rom/ 
#CI_FOLDER is the Location of your CI files. 

#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> 

我用笨3V。 Ty非常適合你的時間。

+0

解決,謝謝,是衝突的另一個功能! – Bogdan

+0

PHP不是JavaScript。換句話說,您不能將代碼片段功能用於PHP代碼,這應該通過代碼窗格上的「JavaScript」標籤顯而易見。 – Sparky

回答

0

請按照以下方式在Codeigniter中重定向。

return redirect('pag'); 

而笨重定向,因爲最終要調用控制器類及其按codeigniters URL結構的方法,不使用PHP擴展。

0

重定向方法ID的一般語法: redirect('controller_name/method_name');

在您的代碼:

public function members() { 
    if($this->session->userdata('is_logged_in')){ 
     redirect('pag/index.php'); //pag is controller name but index.php is not method name 
     //redirect('pag/index'); // try this 
    }else{ 
     redirect('main/restricted'); 
} 

但鑑於()

$this->load->view('pag/index.php'); //index.php is a page located in "applicatoin/view/pag" 

所以這是多麼重定向和查看方法的工作原理。 希望你會明白:)