這讓我很困擾,因為在我今天收到的 PHP Intelephense 的最新更新中,intelephense 不斷顯示未知屬性、函數的錯誤。
特勒芬斯 (1014)
這是我的程式碼:
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Firm extends CI_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * @see https://codeigniter.com/user_guide/general/urls.html */ function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->database(); $this->load->model('Users'); $this->load->model('Projects_Details'); $this->load->model('Categories'); date_default_timezone_set('asia/manila'); } public function index() { $this->load->view('services/default/header'); $this->load->view('services/firm/firm'); $this->load->view('services/default/footer'); } public function services() { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/services/sidebar-menu'); $this->load->view('firm/services/services-1'); } } public function firm_services() { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/firm-services/sidebar-menu'); $this->load->view('firm/firm_services/firm_services'); } } public function add_firm_services() { $permitted_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $user_id = $this->input->post('user_id'); $service_code = substr(str_shuffle($permitted_chars), 0, 10) . rand(10000000, 99999999); $category_id = $this->input->post('category_id'); $sub_category_id = $this->input->post('sub_category_id'); $service_name = $this->input->post('service_name'); $description = $this->input->post('description'); $display_service_name = $service_name; $display_amount = $this->input->post('display_amount'); $ope = rand(0, 1); $status = 1; $vat = 12; $data = array( 'user_id' => $user_id, 'service_code' => $service_code, 'category_id' => $category_id, 'sub_category_id' => $sub_category_id, 'service_name' => $service_name, 'description' => $description, 'display_service_name' => $display_service_name, 'display_amount' => $display_amount, 'ope' => $ope, 'status' => $status, 'vat' => $vat ); $this->db->insert('services', $data); $this->session->set_flashdata('success', 'Service successfully added.'); redirect('Firm/firm_services', 'refresh'); } public function projects() { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/projects/sidebar-menu'); $this->load->view('firm/projects/project_view1'); } } public function edit_projects($id) { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $data['project'] = $this->Projects_Details->get_id($id); $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/projects/sidebar-menu'); $this->load->view('firm/projects/project_view_edit', $data); } } public function update_projects($id) { $data = array( 'project_id' => $this->input->post('project_id'), 'service_id' => $this->input->post('service_id'), 'firm_id' => $this->input->post('firm_id'), 'assigned_id' => $this->input->post('assigned_id'), 'package_id' => $this->input->post('package_id'), 'amount' => $this->input->post('amount'), 'ope' => $this->input->post('ope'), 'start_date' => $this->input->post('start_date'), 'due_date' => $this->input->post('due_date'), 'status' => $this->input->post('status'), 'comment' => $this->input->post('comment'), 'updated_at' => $this->input->post('updated_at'), ); $this->db->where('id', $id); $this->db->update('projects', $data); redirect('Firm/projects', 'refresh'); } public function show_projects($id) { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $data['project'] = $this->Projects_Details->get_id($id); $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/firm-specialist/sidebar-menu'); $this->load->view('firm/projects/project_view_show', $data); } } public function delete_projects($id) { $this->db->delete('projects', ['id' => $id]); redirect('Firm/projects', 'refresh'); } public function specialist_view() { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $this->load->view('services/default/header'); $this->load->view('services/services'); $this->load->view('services/default/footer'); } } public function project_details() { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $this->load->view('services/default/header'); $this->load->view('services/services'); $this->load->view('services/default/footer'); } } public function add_specialist($id) { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $data['project'] = $this->Projects_Details->get_id($id); $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/projects/sidebar-menu'); $this->load->view('firm/add_specialist', $data); } } public function firm_projects() { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/view-project-details/sidebar-menu'); $this->load->view('firm/projects/project_details_view'); } } public function firm_editprojects($id) { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $data['project'] = $this->Projects_Details->get_id_pd($id); $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/view-project-details/sidebar-menu'); $this->load->view('firm/projects/project_details_edit', $data); } } public function firm_showprojects($id) { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $data['project'] = $this->Projects_Details->get_id_pd($id); $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/firm-specialist/sidebar-menu'); $this->load->view('firm/projects/project_details_show', $data); } } public function delete_projects_details($id) { $this->db->delete('projects_details', ['id' => $id]); redirect('Firm/firm_projects', 'refresh'); } public function specialist() { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/firm-specialist/sidebar-menu'); $this->load->view('firm/firm_specialist/firm_specialist_view'); } } public function edit_specialist($id) { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $data['user'] = $this->Users->get_id($id); $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/firm-specialist/sidebar-menu'); $this->load->view('firm/firm_specialist/firm_edit-specialist_view', $data); } } public function show_specialist($id) { $this->load->library('session'); if (!$this->session->userdata('user')) { redirect('login', 'refresh'); } else { $data['user'] = $this->Users->get_id($id); $this->load->view('firm/projects/header-nav'); $this->load->view('default/sidebar/firm/firm-specialist/sidebar-menu'); $this->load->view('firm/firm_specialist/firm_show-specialist_view', $data); } } public function update_specialist($id) { $data = array( 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), 'registered_address' => $this->input->post('registered_address'), 'city' => $this->input->post('city'), 'contact_number' => $this->input->post('contact_number'), 'email' => $this->input->post('email'), ); $this->db->where('id', $id); $this->db->update('users', $data); $this->session->set_flashdata('success', 'User Details Updated Successfully.'); redirect('Firm/specialist', 'refresh'); } public function delete_specialist($id) { $this->Users->delete_id($id); $this->session->set_flashdata('success', 'User Deleted Successfully.'); redirect('Firm/specialist', 'refresh'); } }
有沒有辦法讓 IntelliSense 停止回報錯誤,即使程式碼中沒有錯誤?
您可以使用設定編輯器在 Intelephense 擴充配置中停用 Intelephense > 診斷:未定義的屬性;
或將此行放入settings.json
發生這種情況是因為 CodeIgniter 在運行時透過 CI_Loader 將這些屬性動態注入到控制器中,因為 Inteliphense 找不到程式碼中聲明的這些屬性,因此報告未知屬性錯誤。