2017-11-04 29 views
-1

これに関連するいくつかの質問がありますが、C++やその他の言語があります。このエラーが発生し、私の機能に何が間違っているのか分かりません。 これは私のエラー致命的なエラー:未知のArgumentCountError:機能する引数が少なすぎるAdmincategory :: deletecategory()、

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Admincategory::deletecategory(), 0 passed in F:\xampp\htdocs\digikalamvc\core\app.php on line 34 and exactly 1 expected in F:\xampp\htdocs\digikalamvc\controllers\admincategory.php:50 Stack trace: #0 F:\xampp\htdocs\digikalamvc\core\app.php(34): Admincategory->deletecategory() #1 F:\xampp\htdocs\digikalamvc\index.php(6): App->__construct() #2 {main} thrown in F:\xampp\htdocs\digikalamvc\controllers\admincategory.php on line 50

ですそして、私の機能は次のとおりです。

<?php 

class Admincategory extends Controller 
{ 


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


    function index() 
    { 

     $category = $this->model->getChildren(0); 
     $data = ['category' => $category]; 
     $this->view('admin/category/index', $data); 
    } 


    function showchildren($idcategory) 
    { 

     $categoryInfo = $this->model->categoryInfo($idcategory); 
     $children = $this->model->getChildren($idcategory); 
     $parents = $this->model->getParents($idcategory); 
     $data = ['categoryInfo' => $categoryInfo, 'category' => $children, 'parents' => $parents]; 

     $this->view('admin/category/index', $data); 
    } 


    function addcategory($categoryId = 0, $edit = '') 
    { 

     if (isset($_POST['title'])) { 
      $title = $_POST['title']; 
      $parent = $_POST['parent']; 
      $this->model->addCategory($title, $parent, $edit, $categoryId); 
     } 
     $category = $this->model->getCategory(); 
     $categoryInfo = $this->model->categoryInfo($categoryId); 

     $data = ['category' => $category, 'parentId' => $categoryId, 'edit' => $edit, 'categoryInfo' => $categoryInfo]; 
     $this->view('admin/category/addcategory', $data); 
    } 


    function deletecategory($parentId) 
    { 
     $ids = $_POST['id']; 
     $this->model->deletecategory($ids); 
     header('location:'.URL.'admincategory/showchildren/'.$parentId); 
    } 

} 

?> 

app.phpファイル


<?php 


class App 
{ 

    public $controller = 'index'; 
    public $method = 'index'; 
    public $params = []; 


    function __construct() 
    { 
     if (isset($_GET['url'])){ 
      $url = $_GET['url']; 
      $url = $this->parseUrl($url); 
      $this->controller = $url[0]; 
      unset($url[0]); 
      if (isset($url[1])){ 
       $this->method = $url[1]; 
       unset($url[1]); 
      } 

      $this->params = array_values($url); 
     } 
     $controllerUrl = 'controllers/' . $this->controller . '.php'; 
     if (file_exists($controllerUrl)) { 
      require($controllerUrl); 
      $object = new $this->controller; 

      $object->model($this->controller); 

      if (method_exists($object, $this->method)) { 
       call_user_func_array([$object, $this->method], $this->params); 
      } 
     } 


    } 

    function parseUrl($url) 
    { 
     $url = filter_var($url, FILTER_SANITIZE_URL); 
     $url=rtrim($url,'/'); 
     $url = explode('/', $url); 
     return $url; 
    } 

} 



?> 

とindex.phpの


<?php 

require('views/admin/layout.php'); 
$category = $data['category']; 

$categoryInfo = []; 
if (isset($data['categoryInfo'])) { 
    $categoryInfo = $data['categoryInfo']; 
} 
$parents = []; 
if (isset($data['parents'])) { 
    $parents = $data['parents']; 
    $parents = array_reverse($parents); 
} 

?> 

<style> 

    .w400 { 
     width: 600px; 
    } 

</style> 

<div class="left"> 

    <p class="title"> 
     مدیریت دسته ها 

     (
     <?php foreach ($parents as $row) { ?> 

      <a href="admincategory/showchildren/<?= $row['id']; ?>"> 
       <?= $row['title']; ?> 
      </a> 
      - 

     <?php } ?> 

     <a href="admincategory/<?php if (isset($categoryInfo['id'])) { 
      echo 'showchildren/' . $categoryInfo['id']; 
     } else { 
      echo 'index'; 
     } ?>"> 
      <?php 
      if (isset($categoryInfo['title'])) { 
       echo $categoryInfo['title']; 
      } else { 
       echo 'دسته های اصلی'; 
      } 
      ?> 
     </a> 

     ) 

    </p> 

    <a class="btn_green_small" href="admincategory/addcategory/<?= @$categoryInfo['id']; ?>"> 
     افزودن 
    </a> 


    <a class="btn_red_small" onclick="submitForm();"> 
     حذف 
    </a> 

    <form action="admincategory/deletecategory/<?= @$categoryInfo['id']; ?>" method="post"> 

     <table class="list" cellspacing="0"> 

      <tr> 
       <td> 
        ردیف 
       </td> 

       <td> 
        عنوان دسته 
       </td> 

       <td> 
        مشاهده زیر دسته ها 
       </td> 

       <td> 
        ویرایش 
       </td> 

       <td> 
        انتخاب 
       </td> 

      </tr> 

      <?php 

      foreach ($category as $row) { 
       ?> 

       <tr> 

        <td> 
         <?= $row['id']; ?> 
        </td> 

        <td class="w400"> 
         <?= $row['title']; ?> 
        </td> 

        <td> 
         <a href="admincategory/showchildren/<?= $row['id']; ?>"> 
          <img src="public/images/view_icon.png" class="view"> 
         </a> 
        </td> 

        <td> 
         <a href="admincategory/addcategory/<?= $row['id']; ?>/edit"> 
          <img src="public/images/edit_icon.ico" class="view"> 
         </a> 
        </td> 

        <td> 
         <input type="checkbox" name="id[]" value="<?= $row['id']; ?>"> 
        </td> 

       </tr> 

      <?php } ?> 

     </table> 

    </form> 

</div> 

</div> 


============

が助けようとしてくれてありがとう!

+0

エラーが私には明確なようでトライキャッチしてメソッドの呼び出し元を包む

function deletecategory(string $parentId = ''): void //void is for php7.1 { $ids = $_POST['id']; $this->model->deletecategory($ids); if ('' !== $parentId) { header('location:'.URL.'admincategory/showchildren/'.$parentId); } // AGAIN LOGIC HERE } 

のように見えます – nogad

答えて

0

AdminCategory :: deletecategory($ parentId)はパラメータなしで呼び出されますが、プロトタイプにはデフォルト値がないため例外がスローされることがあります。あなたはポスト要求からデータを取得し、カテゴリがあなたのようなルックスにあなたの方法をリファクタリングすることができ、親を持っていないという可能性は常にありますので:

function deletecategory($parentId = null) 
{ 
    $ids = $_POST['id']; 
    $this->model->deletecategory($ids); 
    if (null !== $parentId) { 
     header('location:'.URL.'admincategory/showchildren/'.$parentId); 
    } 
    // PUT MORE OF YOUR LOGIC HERE, I DO NOT KNOW WHAT SHOULD HAPPEN 
} 

使用している場合は、タイピングを行うことになり、より適切なヒントは、あなたが本当にPARENTIDではなく、その後渡さなければならないことを期待する場合の方法は、

if (method_exists($object, $this->method)) { 
    try { 
     call_user_func_array([$object, $this->method], $this->params); 
    } catch (\Exception $ex) { 
     // HANDLE EXCEPTION HERE 
    } 
} 
関連する問題