【问题标题】:404 - File Not Found Controller or its method is not found: \App\Controllers\Ivy::codeignitor404 - 文件未找到控制器或其方法未找到:\App\Controllers\Ivy::codeigniter
【发布时间】:2021-11-11 20:41:30
【问题描述】:

我有一个控制器,名为 About:

<?php

namespace App\Controllers;

class About extends BaseController
{
     public function __construct()
    {
        
        $this->data['site_title'] = "About Us";
    }

    public function index()
    {
        //return view('welcome_message');
        return $this->_renderPage('About/index', $this->data);

    }
}

render_page 函数在 basecontroller 中如下:

 public function _renderPage($view, $data = [])
{
    $data = array_merge($this->data, $data);
    $data['_html_content'] = view('Home/' . $view, $data);
    return view('Home/page', $data);
}

我的文件夹结构是:

  1. 应用程序

  2.  -Controllers
    
  3.             - About
    
  4.             - Home
    
  5.             - Contact
    

我的视图文件如下:

  1. 观看次数
  2.   -Home
    
  3.         -Contact
                     - index.php
    
  4.         -About
                     - index.php
    
  5.         - ...
    

我参考的方式是

<a href="<?php echo site_url('about') ?>">About</a>

我的 .htaccess 文件有这行代码:

 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f    
 RewriteCond %{REQUEST_FILENAME} !-d    
 RewriteRule ^(.+)$ index.php/$1 [L]

为什么我仍然收到错误:404 - 找不到文件 输入 url 时找不到控制器或其方法:\App\Controllers\Ivy::codeignitor:

localhost:8080/myproject/about

【问题讨论】:

  • 你添加路由到 Routes.php 了吗?
  • 是的。如,$routes-&gt;add('about', 'About::index');
  • 您能否包含您的视图文件以确保所有内容都存在?
  • 我已经进行了编辑并显示了我的文件夹结构以供查看

标签: .htaccess codeigniter


【解决方案1】:

尝试&lt;?= base_url()?&gt; 而不是&lt;?= site_url()?&gt;

【讨论】:

    猜你喜欢
    • 2016-10-12
    • 2020-10-05
    • 2013-10-04
    • 2020-11-24
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 2016-06-23
    相关资源
    最近更新 更多