【问题标题】:Codeigniter navigation doesn't workCodeigniter 导航不起作用
【发布时间】:2015-10-10 12:35:15
【问题描述】:

我创建了一个新应用程序,应用程序/视图中只有 2 个视图和 1 个控制器。我只想通过控制器从视图中的 page1 转到视图中的 page2。

这是整个代码: https://www.dropbox.com/s/cytt5azgerrbsg2/Afstudeerproject.zip?dl=0

相关代码

视图 1:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Welcome to CodeIgniter</title>
    </head>
    <body>
        <div id="container">
             <h1>Welcome to CodeIgniter!</h1>
             <div id="body">
                 <?= form_open(site_url('Welcome/steven')) ?>
                <input type="file" name="userfile" />
                <p><input type="submit" value="submit" name="submit" /></p>
                <?= form_close() ?>
            </div>
        </div>
    </body>
</html>

视图 2:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Welcome to CodeIgniter</title>
    </head>
    <body>
        <div id="container">
             <h1>Welcome to CodeIgniter!</h1>
             <div id="body">
                <?= form_open(site_url('welcome')) ?>
                <input type="file" name="userfile" />
                <p><input type="submit" value="submit" name="submit" /></p>
                <?= form_close() ?>
             </div>
         </div>
    </body>
</html>

控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
    public function index() {
        $this->load->view('welcome_message');
     }
    public function steven() {
        $this->load->view('welcome_secondpage');
    }
}

routes.php:

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

config.php:

$config['index_page'] = '';
$config['base_url'] = '';

自动加载.php:

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

其余文件都是标准的CodeIgnitor

【问题讨论】:

  • 能否将相关代码发布到 StackOverflow 上?我觉得从网上下载随机 zip 文件不安全。

标签: php codeigniter model-view-controller


【解决方案1】:

在你的配置文件中分配这个$config['index_page'] = 'index.php';

【讨论】:

  • 多么奇怪。尝试了10次,但它有效。谢谢!
猜你喜欢
  • 1970-01-01
  • 2023-03-11
  • 1970-01-01
  • 2018-07-22
  • 2019-01-15
  • 2018-04-01
  • 2013-07-12
相关资源
最近更新 更多