【问题标题】:Listing okay, but all other functions are not working上市没问题,但所有其他功能都不起作用
【发布时间】:2018-08-18 11:38:40
【问题描述】:

我对 Codeigniter 和 Grocery CRUD 完全陌生,但我非常喜欢这个概念,所以我正在尝试使用这些框架制作我的小应用程序。

所以,现在登录系统正在运行,在“主页”页面上登录后,我看到了我的 Grocery CRUD 表,它已填满,到目前为止一切正常......

我的问题是,我不能使用任何功能:添加、编辑、查看、搜索不起作用,它给了我 404 错误,例如这是一个编辑链接:

http://subdomain.mysite.com/index.php/home/edit/1

该网站位于子域上,我不知道是否相关。

这是我的 base_url:

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

如果我把它改成'',base_url();方法没有给我正确的值,我认为这是因为子域。

这是我完整的“主页”视图:

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>My system</title>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>bootstrap/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <h1 class="page-header text-center">My system</h1>
    <div class="row">
    <div class="container text-right">
            <?php
                $user = $this->session->userdata('user');
                extract($user);
            ?>
        <p class="d-inline"><b>Logged in as:</b> <i><?php echo $fname; ?></i></p>
    </div>
        <div class="container">
            <?php 
            $crud = new grocery_CRUD();
            $this->grocery_crud->set_table('mobil_table');
            $this->grocery_crud->columns('mobile_number', 'package_name', 'package_date');

            $output = $this->grocery_crud->render();
            $this->load->view('mobil.php', $output); ?>
            <a href="<?php echo base_url(); ?>index.php/user/logout" class="btn btn-danger">Logout</a>
        </div>
    </div>
</div>
</body>
</html>

我的路线:

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

$route['home'] = 'user/home';

我应该更正什么才能使这些功能在此页面上正常工作?谢谢 :)

【问题讨论】:

    标签: php codeigniter grocery-crud


    【解决方案1】:

    您必须通过您的控制器/方法方式访问您的编辑页面

    如果你的控制器是用户并且它有一个带有参数名称 $id 的函数编辑,你的访问 url 将是:

    http://subdomain.mysite.com/index.php/user/edit/1
    

    或为其定义新路线:

    $route['home/edit'] = 'user/edit';
    

    或者更清楚

    $route['home/edit/(:num)'] = 'user/edit/$1';
    

    但是您可以通过以下步骤获得干净的网址:

    首先使用以下代码在您的网站根文件夹中创建一个 .htaccess 文件:

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

    改变之后:

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

    $config['index_page'] = '';
    

    做完以上步骤后,你就可以在urls中不带index.php访问你的url了

    例如:

    http://subdomain.mysite.com/index.php/user/edit/1
    

    会变成

    http://subdomain.mysite.com/user/edit/1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      相关资源
      最近更新 更多