php - 尝试在 Codeigniter 中传递 url 中的值时遇到 404 页面未找到

标签 php codeigniter uri

我正在尝试在网址中传递值

http://192.168.1.136/dashboard/Projects/CodeIgniter-3.1.11/index.php/calls/call_id

并且面临 404 页面未找到错误。

我想将 call_id 传递给 Controller ​​。请告诉我我做错了什么。

这是 Controller

  class Calls extends CI_Controller {

    // I WANT TO ACCESS call_id HERE
    function __construct() {
      parent::__construct();
    }

    public function index($abc) {

      $this->load->helper('url');
      $call =  $this->uri->segment(3);
      $data = array('call_id' => $call, 'bar' => 'world');
      $this->load->view('Pages/MyAjax.php', $data);
    }
  }

这是路由器配置

defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

这是config.php

defined('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = '';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FALSE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
$config['allow_get_array'] = TRUE;
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['error_views_path'] = '';
$config['cache_path'] = '';
$config['cache_query_string'] = FALSE;
$config['encryption_key'] = '';
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;
$config['standardize_newlines'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = '';

我想访问 Controller 中的call_id。

最佳答案

index() 添加参数,如下所示 index($call_id = NULL)

Controller

  class Calls extends CI_Controller {

    function __construct() {
      parent::__construct();
    }

    public function index($call_id = NULL) {

      // $this->load->helper('url');
      // $call =  $this->uri->segment(3);
      $data = array('call_id' => $call_id, 'bar' => 'world');
      $this->load->view('Pages/MyAjax.php', $data);
    }
  }

和网址

http://192.168.1.136/dashboard/Projects/CodeIgniter-3.1.11/index.php/calls/index/30

上述网址 30 中的最后一段是 call_id

关于php - 尝试在 Codeigniter 中传递 url 中的值时遇到 404 页面未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59965613/

相关文章:

php - "Connect failed: Access denied for user ' root '@' localhost ' (using password: YES)"来自php函数

javascript - CodeIgniter - AJAX 生成元素内的 AJAX 分页

c# - 是否有一个概述来查看哪些 UriComponents 返回 Uri 的内容?

用于处理路径/URI 的 JavaScript 或查询库

Tomcat.8.5.15 不接受 URI 中的 "\"并抛出 IllegalArgumentException

php - Curl:保存文件而不是打开文件

php - Wordpress Docker容器无法上传主题

php - MySql 批量插入

php - CodeIgniter 水印

javascript - Codeigniter PHP 自动完成