控制器没有调用添加动作方法 - 代码点火器

时间:2015-05-30 12:02:42

标签: php codeigniter model-view-controller

Controller不会在代码点火器中调用add action方法。

我的控制器没有调用添加视图或没有调用add方法,它显示404错误,或者它可能是url或者类似路径的问题。

class Incomeexpense extends MX_Controller {

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

  }


  function add()
  {
    meta['page_title'] = $this->lang->line("Incomeexpense");
    $data['page_title'] = $this->lang->line("Incomeexpense");
    $this->load->view('commons/header', $meta);
    $this->load->view('add',$data);
    $this->load->view('commons/footer');
  }

}

1 个答案:

答案 0 :(得分:0)

因为您使用的是HMVC的MX_Controller

在“应用程序”文件夹中选中“如果我刚刚命名了module_folder”作为示例,您可以重命名它。

modules
modules > module_folder 
modules > module_folder > controllers 
modules > module_folder > controllers > Incomeexpense.php
modules > module_folder > views
modules > module_folder > views > add.php
modules > module_folder > views > commons > header.php
modules > module_folder > views > commons > footer.php

Route.php

$route['incomeexpense'] = "module_folder/incomeexpense/index";
$route['incomeexpense/add'] = "module_folder/incomeexpense/add";

您的网址将是

http://localhost/project/incomeexpense/add

我不确定您是否删除了index.php然后

http://localhost/project/index.php/incomeexpense/add

控制器

<?php

class Incomeexpense extends MX_Controller {

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

public function index() {

}

public function add() {
    $this->load->lang('some_file', 'english');

    $meta['page_title'] = $this->lang->line("Incomeexpense");
    $data['page_title'] = $this->lang->line("Incomeexpense");
    $this->load->view('commons/header', $meta);
    $this->load->view('add',$data);
    $this->load->view('commons/footer');
}
}

How To Use HMVC