默认控制器不工作

时间:2015-09-06 07:02:38

标签: php .htaccess codeigniter routes

我有一个问题。

我无法访问默认控制器。我尝试修改路径 htaccess 这么多次,但默认控制器不起作用。

我的routes.php

$route['default_controller'] = 'front';
$route['page/(:any)'] = "front/page/$1";
$route['cake/(:any)'] = 'front/cake/$1';
$route['product'] = 'front/allcakescategory';
$route['login'] = 'front/login';
$route['register'] = 'front/register';
$route['logout'] = 'front/logout';
$route['invoice/(:any)'] = 'cart/invoice/$1';
$route['404_override'] = '';

我的.htaccess文件

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  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>

我非常感谢很多帮助。

之前谢谢

UPDATE front.php(控制器)

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

/**
*
*/
class Front extends CI_Controller
{

    function __construct(){
        parent::__construct();
        $this->load->model('globalfunc');
        $this->load->model('cartmodel');

    }


    function index(){
        $data['cakes'] = $this->globalfunc->getCakes();
        $data['sliders'] = $this->globalfunc->getSlider();
        $data['title'] = 'Home';
        $this->load->view('front/home',$data);
    }

    public function login(){
        if(!is_login()){
            $data['title'] = 'Login';
            $data['redirectLogin'] = 'user/action/login?redirect=/';
            $this->load->view('front/login',$data);
        }else{
            redirect(base_url());
        }
    }

    public function register(){
        if(!is_login()){
            $data['title'] = 'Register';
            $data['redirectRegister'] = 'user/action/register?redirect=register';
            $data['cities'] = $this->globalfunc->getDelivery();
            $this->load->view('front/registerHome',$data);
        }else {
            redirect(base_url());
        }
    }

    public function page($slug){
        $data['content'] = $this->globalfunc->getSlugId($slug);
        if(!empty($data['content'])){
            $data['title'] = $data['content']->title;
            $this->load->view('front/page',$data);
        }else {
            echo 'not found';
        }
    }

    public function forget_password(){
        $data['title'] = 'Forget Password';
        $this->load->view('front/forget_pass',$data);

        if($this->input->post('forget_password')){
            $email_address = $this->input->post('email_address');
            $get = $this->globalfunc->validate(array('email_address' => $email_address),'user');
            if(!empty($get)){
                $data = array(
                    'user_id' => $get->id,
                    'key' => md5($email_address.time()),
                );
                $config = Array(
                    'protocol' => 'smtp',
                    'smtp_host' => 'ssl://smtp.mandrillapp.com',
                    'smtp_port' => 465,
                    'smtp_user' => 'yosua.reinaldo@gmail.com',
                    'smtp_pass' => 'nbKsjydlNFv4pONa3g-1bA',
                    'mailtype' => 'html',
                    'charset' => 'iso-8859-1',
                    'wordwrap' => TRUE,
                );
                $msg = 'Click <a target="_blank" href="'.base_url('front/reset/'.$data['key']).'">here</a> to reset your password ';

                $this->load->library('email', $config);
                $this->email->set_newline("\r\n");
                $this->email->from('yosua.reinaldo@gmail.com', 'Reinaldo Yosua');
                $this->email->reply_to('yosua.reinaldo@gmail.com', 'Reinaldo Yosua');
                $this->email->to($email_address);
                $this->email->subject('Karaya Reset Password');
                $this->email->message($msg);
                $this->email->send();

                $this->db->insert('forget_password',$data);
            }

            else{
                echo 'not found';
            }
        }


    }

    public function reset($key){
        $get = $this->globalfunc->validate(array('key' => $key, 'status' => 0),'forget_password');
        if(!empty($get)){
            $data['title'] = 'Reset Password';
            $this->load->view('front/forget_pass',$data);
        }else{
            echo 'not found';
        }
    }

    /*public function allCakes(){
        $data['title'] = 'Our Product';
        $data['cakes'] = $this->globalfunc->getCakes();
        $this->load->view('front/list_cake',$data);
    }*/

    public function AllCakesCategory(){
        $data['title'] = 'Our Product';
        $data['cakes'] = $this->globalfunc->getCakes();
        $this->load->view('front/list_cake',$data);
    }

    public function cake($id, $slug =''){
        $data['cake'] = $this->globalfunc->getCake($id);
        $data['title'] = $data['cake']->name;
        $data['variations'] = $this->globalfunc->getVariation($id);
        $this->load->view('front/cake',$data);
    }

    public function logout(){
        $this->session->sess_destroy();
        redirect(base_url());
    }

    public function forget(){

    }
}

1 个答案:

答案 0 :(得分:1)

从Front.php将控制器名称更新为Front,将控制器文件Front.php更新为Front.php。最近我也遇到了这个错误。