【问题标题】:CodeIgniter base_url leads to page not foundCodeIgniter base_url 导致找不到页面
【发布时间】:2017-11-22 12:43:31
【问题描述】:

我正在使用 CodeIgniter,而且我是新手,因为我从事 Web 开发。 我对来自 CI 的 base_url 有疑问:它会导致 404 Page not found。

这是页面的参考:

<li><a href="<?=base_url('Usual/novo_usual')?>">Cadastrar</a></li>

控制器的功能:

function novo_usual(){
    $this->load->view('html-header');
    $this->load->view('html-footer');
    $this->load->view('cadastro_usual');
}

我的控制器名称文件以大写开头,如 Usual.php,并扩展为 CI_Controller。

我的 altoloado.php:

$autoload['helper'] = array('url','html','form','funcoes');

我的路线.php:

$route['default_controller'] = 'Home';

最后是 .htaccess 文件

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>

【问题讨论】:

  • 您忘记为Usual/novo_usual定义路由
  • 你试过只使用 base_url(); ?

标签: php html codeigniter


【解决方案1】:

参见 \application\config\config.php

$config['base_url'] = '';

将您的网站网址写入此网址。

例如

$config['base_url'] = 'http://test.com/';

现在如果你使用 base_url('Usual/novo_usual') 这等于http://test.com/Usual/novo_usual

【讨论】:

  • 我设置了这个 '$config['base_url'] = 'localhost/geoportal/';' ,但仍然无法正常工作。
  • 控制这样做
  • Cadastrar
  • 保存并在说问题是它或一切好之后去链接. not base_url 可能有问题
【解决方案2】:

如果你不设置网站网址,那么首先设置它

 //Site URL Path : application\config\config.php

$config['base_url'] = 'http://localhost/site_name';

然后添加这个:

<?php 

  echo site_url('Usual/novo_usual');

//OR

 echo base_url('Usual/novo_usual'); ?>

【讨论】:

    【解决方案3】:

    首先你需要设置你的文件夹路径

    \application\config\config.php

    $config['base_url'] = '';
    

    例如

    $config['base_url'] = 'http://localhost/folder/';
    

    【讨论】:

      【解决方案4】:

      我已经设法解决了。 原来我的项目名称以“G”开头,在我的网址中我用“g”来称呼它。 谢谢大家。

      【讨论】:

        猜你喜欢
        相关资源
        最近更新 更多
        热门标签