【问题标题】:Default Controller not Working默认控制器不工作
【发布时间】:2015-12-01 23:05:10
【问题描述】:

我有问题。

我无法访问默认控制器。我试图修改我的 routes 和 htaccess 这么多次,但默认控制器不起作用。

我的路线.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>

我真的很感激许多帮助。 谢谢之前

更新 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(){

    }
}

【问题讨论】:

  • 在发布任何帮助之前,我们需要知道您当前用于路由的框架
  • 他已经标记了它。代码点火器
  • 尝试停止/删除您的 .htaccess 文件,然后尝试运行您的默认控制器
  • @Manee.O.H :谢谢你之前的回答。但我需要在没有 index.php 的情况下自定义我的网址
  • 别听这个说。大错特错。请自行检查documentation。 "类名必须以大写字母开头。"

标签: php .htaccess codeigniter routes


【解决方案1】:

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

【讨论】:

  • 你的答案,但什么也没发生
  • 点击 url 时显示的错误是什么...并尝试通过注释 .htaccess 文件的代码。 @AdityaRahadian
  • 如果网站已经上线,你能分享一下网址吗?
  • 这个错误可能出现在 1) 错误是 .htaccess 文件 2) 控制器文件名无效
  • 控制器可能没问题,先生。我认为 htaccess 或 routes.php 中的错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-03
  • 1970-01-01
  • 2015-04-02
  • 1970-01-01
  • 2017-02-17
相关资源
最近更新 更多