Why is controller not defined? Error: Undefined index: controller
Why is controller not defined? Error: Undefined index: controller
我是第一次尝试 Laravel 5,我很早就遇到了 运行 问题。如果有人可以向我解释,我将不胜感激。
我的 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 is invalid."}
谁能解释一下我是如何正确设置 $controller 和 $action 的?请原谅我的菜鸟,我是第一次尝试学习框架!
您能否确认您的 $params
索引与您的请求名称匹配?另外,您能否提供为请求构建视图的代码?
好的,我解决了我的问题。这听起来真的很愚蠢,但对于一个框架/MVC 新手来说,它令人困惑......
我忘记创建控制器层了!事实上我有,但没有正确引用它。
现在我在名为 '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();
}
伙计们,把你的模型和控制器分开!感谢您的时间和耐心等待评论的人。
我是第一次尝试 Laravel 5,我很早就遇到了 运行 问题。如果有人可以向我解释,我将不胜感激。
我的 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 is invalid."}
谁能解释一下我是如何正确设置 $controller 和 $action 的?请原谅我的菜鸟,我是第一次尝试学习框架!
您能否确认您的 $params
索引与您的请求名称匹配?另外,您能否提供为请求构建视图的代码?
好的,我解决了我的问题。这听起来真的很愚蠢,但对于一个框架/MVC 新手来说,它令人困惑......
我忘记创建控制器层了!事实上我有,但没有正确引用它。
现在我在名为 '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();
}
伙计们,把你的模型和控制器分开!感谢您的时间和耐心等待评论的人。