Php 为什么控制器没有定义?错误:未定义索引:控制器

Php 为什么控制器没有定义?错误:未定义索引:控制器,php,laravel,controller,Php,Laravel,Controller,我第一次试用Laravel 5,但我很早就遇到了一个问题。如果有人能给我解释一下,我将非常感激 my index.php脚本的第一行如下所示: // Define path to data folder define('DATA_PATH', realpath(dirname(__FILE__).'/data')); //include our models include_once 'models/TodoItem.php'; try { //get all of the par

我第一次试用Laravel 5,但我很早就遇到了一个问题。如果有人能给我解释一下,我将非常感激

my index.php脚本的第一行如下所示:

// Define path to data folder
define('DATA_PATH', realpath(dirname(__FILE__).'/data'));

//include our models
include_once 'models/TodoItem.php';


try {
    //get all of the parameters in the POST/GET request
    $params = $_REQUEST;

    //get the controller and format it correctly so the first
    //letter is always capitalized
    $controller = ucfirst(strtolower($params['controller']));

    //get the action and format it correctly so all the
    //letters are not capitalized, and append 'Action'
    $action = strtolower($params['action']).'Action';
...
运行时会引发以下异常:

(!)注意:未定义索引:第15行/index.php中的控制器 调用堆栈

(!)注意:未定义索引:第19行/index.php中的操作 调用堆栈

{“success”:false,“errormsg”:“控制器无效。”}


有人能解释一下我是如何正确设置$controller和$action的吗?请原谅我的无知,我第一次尝试学习一个框架

您能否确认您的
$params
索引与您的请求名称匹配?另外,您能否提供为请求构建视图的代码

好的,我解决了我的问题。这听起来很愚蠢,但对于一个框架/MVC noob来说,这是令人困惑的

我忽略了创建控制器层!事实上,我有,但没有正确地引用它

现在,我在一个名为“controllers”的文件夹中有一个脚本,它从$params(即我在url/post方法中发送的任何内容)构造了一个数组。一切都很好!以下是我的基本控制器功能:

class Todo
{
  private $_params;

  public function __construct($params)
  {
    $this->_params = $params;
  }

  public function createAction()
  {
    // create a todo item
    $todo = new TodoItem();
    $todo->title = $this->_params['title'];
    $todo->description = $this->_params['description'];
    $todo->due_date = $this ->_params['due_date'];
    $todo->is_done = 'false';

    //pass the user's username and password to authenticate the user
    $todo->save($this->_params['username'], $this->_params['userpass']);

    //return the todo item in array format
    return $todo->toArray();
  }

各位,把你们的模型和控制器分开!感谢您的时间和耐心为那些评论

请执行
打印($params)
并编辑答案,此时$params只是一个空数组。它返回“Array()”@Leon如果$params数组为空,则无法访问$params['controller']。您正在尝试访问不存在的内容!请将此添加为对问题的评论。我需要50多名代表来完成此操作。。我想?