You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter项目加载视图test.php失败,请求问题排查

CodeIgniter视图加载失败排查方案

问题背景

我正在维护一个由其他开发者创建的CodeIgniter现有项目,尝试加载视图文件test.php时,出现报错:

Unable to load the requested file: test.php

控制器相关代码

$customer_id = $this->session->userdata('customer_id');
$customer = $this->site->getRowById('customer_information', 'customer_id', $customer_id);
if($customer->sales_active != 1){
    $this->session->set_flashdata('danger_msg', 'Sorry, You have not active !');
    redirect('customer/customer_dashboard');
}
$company_info = $this->site->getRowsByCondition('company_information');
$selectFields ='c.id as currency_id,c.img,c.decimal_curr, w.userid, w.id as wallet_id,w.updated_on, c.currency, w.address, w.balance,w.live_balance,w.usdt_price,w.total_usd,c.decimal_curr';
$where = array('c.status' => 1);
$where_in = array('w.userid',  $customer_id);
$orderBy = array('c.id','asc');
$joins = array('user_wallet w'=>'c.id = w.currency_id');
$getWallet =  $this->site->getleftJoinedTableData('currency_master c',$joins,$where,$selectFields,'','','','','',$orderBy,'',$where_in)->result_array();
$new_currency = $this->site->customQuery("select * from bizzc_currency_master where status = 1 and id not in (select currency_id from bizzc_user_wallet where userid = '$customer_id')")->result_array();
// echo 'curr';die;
$data = array(
    'title' =>  'My Wallet',
    'customer' =>  objectToArray($customer),
    'customer_id' =>  $customer_id,
    'wallet' =>  $getWallet,
    'new_currency' =>  $new_currency,
    'company_info' =>  $company_info
);
$content = $this->parser->parse('website/customer/currency', $data, true);
$this->template->full_customer_html_view($content);
$this->load->view('test');

排查要点

  • 视图路径与存在性:CodeIgniter默认从application/views/目录加载视图,若test.php不在根目录,需指定完整相对路径(如website/customer/test);确认文件真实存在,文件名大小写与代码一致(Linux服务器区分大小写)。
  • 输出顺序冲突:代码中$this->template->full_customer_html_view($content)通常会直接输出完整HTTP响应(含HTML头、尾),此时再调用$this->load->view('test')会因响应已发送导致加载失败。需调整逻辑:要么将test.php内容整合到模板中,要么先加载test视图并合并到$content后再调用模板输出。
  • 文件权限问题:确保test.php的权限为644,所在目录权限为755,Web服务器进程(如www-data、apache)拥有读取权限。
  • 视图目录配置:检查application/config/config.php中的$config['view_folder'],若该配置指定了自定义目录,需将test.php放入对应目录。

内容的提问来源于stack exchange,提问作者amit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 15:25:20