如何调试“缺少Skill :: delskill的参数1”?

时间:2016-10-22 13:04:38

标签: codeigniter

Error:  A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Skill::delskill()

Filename: controllers/Skill.php

Line Number: 75

Backtrace:

File: /var/www/html/tatui/application/controllers/Skill.php
Line: 75
Function: _error_handler

File: /var/www/html/tatui/index.php
Line: 292
Function: require_once
//

这是代码,剩下的代码工作正常

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Skill extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        //$this->load->library('session');
        $this->load->helper(array('form', 'url', 'html'));
        $this->load->library('form_validation');        
    }
     public function construct_pages($page, $data) {           
          $this->load->view('templates/header', $data);
          $this->load->view('pages/'.$page);
          $this->load->view('templates/footer');
      }
    // checks login using in built validation


   public function index()
    {

      $this->load->helper('form');
      $this->load->view('pages/AddSkill');

    }
    public function skill_validate(){

      $this`enter code here`->load->library('form_validation');
      $this->form_validation->set_rules('skillid', 'skillid', 'required|max_length[15]');
      $this->form_validation->set_rules('skillname', 'SkillName', 'required|max_length[25]');
      $this->form_validation->set_rules('skilldescription', 'skilldescription', 'required|max_length[70]');
      $this->form_validation->set_rules('skillgroup', 'skillgroup', 'required');

      if($this->form_validation->run()){

        $this->load->model('Getskills', '', TRUE);
        $skill = $this->input->post('skillid');
        $skillExisted = $this->Getskills->getskill($skill);
        if($skillExisted){

          echo "Skill Already Existed";
          $this->load->helper('form');
          $this->load->view('pages/AddSkill');

        }
        else{
          $data = array(
          'SkillId' =>  $this->input->post('skillid'),
          'SkillDescription' => $this->input->post('skilldescription'),
          'SkillGroup' => $this->input->post('skillgroup'),
          'SkillName' => $this->input->post('skillname')
         );

         $inserted = $this->Getskills->insert_skill($data);
          if($inserted){

            echo "Inserted Successfully";
            $this->load->view('pages/AddSkill');        
          }        
          else{

            echo  "Please contact Support Team";
          }
      }

    }
    else{

       echo  "Please contact Support Team";
    }

  }

此部分无法正常工作?

  public function delskill($data) {

      $this->db->where(array('Skillid' , 'Skillname' , 'Skillgroup' , 'Skilldescription'));
      $this->db->delete('Skills');

    }

  }

有人知道它不起作用的实际原因吗?

2 个答案:

答案 0 :(得分:0)

根据你的问题,它显示错误,如缺少Skill :: delskill()的参数1 它意味着你在调用delskill函数时你没有将任何参数传递给它,但你创建了这个函数,其中一个参数作为公共函数delskill($ data){...},所以,你需要传递一个参数在delskill功能。但我查看了你的delskill函数,没有使用它,因为你没有将那个传递参数用于该函数,以及条件错误的那个函数。

答案 1 :(得分:0)

如果您不确定始终发送默认参数,则需要向方法或函数发送默认参数。

 public function delskill($data = '') {
     if (isset($data) && is_array($data)) {
         $this->db->where(array('Skillid' , 'Skillname' , 'Skillgroup' , 'Skilldescription'), $data);
         $this->db->delete('Skills');
     }
}

注意:根据您的代码,您要从多列中删除。如果您将空白数据作为args发送并执行查询,则将面临数据丢失问题。确保始终发送有效的删除请求,拥有安全的SQL。

相关问题