douxuan1284 2014-09-16 19:15
浏览 39

无法重定向到新页面 - CodeIgniter

I have a login system that works, but on the redirect function it gives me the error The requested URL "http://localhost/musiclear/index.php/welcome" cannot be found or is not available. Please check the spelling or try again later.

This is where I am using it (login.php):

    function validate_credentials() {

    $this->load->model('membership_model');
    $query = $this->membership_model->validate();

    if ($query) { // if users credentials validated
        $data = array('usernames' => $this->input->post('username'), 
        'is_logged_in' => true);

        $this->session->set_userdata($data); //set session data
        redirect('welcome', 'refresh'); //redirect to home page
    } else { //incorrect username or password
        $this->index();
    }
}

This is where I am directing it to (welcome.php):

class Welcome extends CI_Controller {

public function index() {
    $this->home();
}

public function home() {
    $this->load->model('model_users');

    $data['title'] = 'MVC Cool Title'; // $title
    $data['page_header'] = 'Intro to MVC Design';
    $data['firstnames'] = $this->model_users->getFirstNames();
    // just stored the array of objects into $data['firstnames] it will be accessible in the views as $firstnames

    $data['users'] = $this->model_users->getUsers();

    $this->load->view('home_view', $data);
}
}

Im thinking it is something wrong with the path, or where its linking to but im not sure. This is my directory setup:

file setup

Can someone please tell me whats wrong and how I can make it link to my page? Thanks so much

  • 写回答

1条回答 默认 最新

  • dongliao9233 2014-09-16 20:58
    关注

    Have you created the .htaccess in your application folder?

    Maybe this can work for your project:

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

    You are welcome

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分