【问题标题】:home page is not opening in codeigniter主页未在 codeigniter 中打开
【发布时间】:2019-02-13 23:18:49
【问题描述】:

在我正确配置的codeigniter中主页没有响应,我尝试调试但找不到错误

请看下面的代码

config/routes.php

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

$route['default_controller'] = 'home';
//$route['404_override'] = '';
//this for the admininstration console
$route['admin'] = 'admin/dashboard';
$route['admin/media/(:any)']= 'admin/media/$1';

controllers/home.php

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

class Home extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('form_validation');
                $this->load->model('Category_model');
                $this->load->model('Product_model');
                $this->load->model('Option_model');
                $this->load->model('ratenreview_model');

                //load Dentkart library
                $this->load->library('Banners');
                $this->load->library('Menus');
                $this->load->model(array('location_model'));
                $this->load->model('Customer_model');
        $this->load->model('Testimonial_model');
       $this->load->library('dentkart');
                $this->load->helper(array('formatting_helper'));
                $this->customer = $this->dentkart->customer();

    }
private function index() {

                $this->data['page'] = "Home";
                $this->ratenreview_model->ecash_event_date('dob');
                $this->ratenreview_model->ecash_event_date('clinic_anniversary');
                $this->ratenreview_model->ecash_event_date('marrg_aniversary');

                $arrCatHome  =array(440,468,472,568);
                for($i=0;$i<count($arrCatHome);$i++){

                        $data['arrCategories'][] = $this->Category_model->get_category($arrCatHome[$i]);
                        $data['products'][$arrCatHome[$i]] = $this->Product_model->get_homepage_category_products($arrCatHome[$i]);

                        foreach ($data['products'][$arrCatHome[$i]] as &$p){
                                $p->images  = (array)json_decode($p->images);
                                $p->options = $this->Option_model->get_product_options($p->id);
                        }
                }

                $data['arrShopByBrand'] = $this->Product_model->get_shop_brands();
                //$data['arrHomeProducts'] = $this->Product_model->getHomeProducts();
                //get all booktype
        //$data['arrBooktype'] = $this->Product_model->get_book_types();

        $data['arrTestimonial'] = $this->Testimonial_model->getTestimonialList();
        $this->load->view('vwHome',$data);
    }
}

.htaccess

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L]

并且还尝试更改 routs 中的默认控制器,导致 404 错误 请帮我解决问题

【问题讨论】:

    标签: php codeigniter mysqli configuration


    【解决方案1】:

    private function index() { 应该是public function index() {

    路由器无法查看/显示私有方法。控制器中的私有方法应该很少使用,通常只用于常用的类的较小“帮助”函数。

    【讨论】:

    • 是的,我改成公共函数 index() 还是没来
    • Home 必须是 Home.php,因为在 Linux 上区分大小写。尝试去 index.php/home 看看是否至少有效
    • 我试过alex还是不行,不知道问题出在哪里
    • 我尝试将主页更改为管理页面,然后显示 404 页面未找到 @Alex
    【解决方案2】:

    只需将Home 控制器中的private function index() 更改为公共函数

    【讨论】:

      【解决方案3】:

      更改 route.php

       $route['default_controller'] = 'Home';
      $route['404_override'] = '';
      $route['translate_uri_dashes'] = FALSE;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-04-04
        • 2016-06-13
        • 1970-01-01
        • 2012-10-21
        • 1970-01-01
        • 2017-11-14
        • 2017-08-14
        • 1970-01-01
        相关资源
        最近更新 更多