我在视图中使用form_open()
helper方法来指示控制器方法处理表单提交操作,并在app\Config\Routes.php
中定义路由。
我仍然收到错误Can't find a route for 'registrations/index'
。
请协助解决此问题。下面提供了代码片段。
错误:
register.php
视图文件:
<?php echo form_open('/registrations/index'); ?>
Registrations.php
控制器:
class Registrations extends BaseController {
public function index() {
$data['coursename'] = $this->getCourseName();
log_message('info','name field >' . $this->request->getVar('iname') . '<<');
echo view('templates/header');
echo view('pages/register', $data);
echo view('templates/footer');
}
Routes.php
$routes->get('/registrations/index', 'Registrations::index');
2条答案
按热度按时间carvr3hs1#
解释:
上面的代码行将创建一个表单,该表单指向您的站点URL加上“/registrations/index”URI段,如下所示:
如果仔细看一下上面自动生成的
form
开始标记,这实际上是一个POST
HTTP请求,但是您在app\Config\Routes.php
文件中使用->get(...)
方法定义了路由。解决方案:
代替(
Routes.php
):使用这个:
->post(...)
的用法。*资源:Form Helper。
8i9zcol22#
我认为您的AutoRoutes默认设置为false。
将此行添加到
Routes.php
中