当用户访问我的页面时,他们会被带到主屏幕(目前有一个标题和一个按钮)。一个按钮是开始游戏,它应该重定向到一个有游戏板的视图。我如何将该信息从按钮发送到控制器以访问新视图
这是在我看来的按钮(按钮应该将信息发送到功能点击())
<form id="start" action="index.php/click" method="POST" >
<input type="submit" name="start" value="startGame" />
</form>
现在在控制器index.php
function click()
{
$action = $_POST['submit'];
if($action == 'startGame')
{
$this->load->view('welcome_message');
}
}
我让它加载welcome_message只是为了学习如何重定向。(我的小组还没有完全构建游戏板页面)
有几件事需要更改
1.尝试使用其他名称代替控制器的"index.php"
。例如CCD_ 2。我认为控制器名称不允许使用index.php。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
}
public function click()
{
$action = $this->input->post('start'); // $_POST['start']; also works.
if($action == 'startGame')
{
$this->load->view('welcome_message');
}
}
}
2.在您的视图中,按如下方式更改action
的值。
<form id="start" action="test/click" method="POST" >
<input type="submit" name="start" value="startGame" />
</form>
这应该行得通。谢谢
try,
function click()
{
$action = $_POST['start'];
if($action == 'startGame')
{
$this->load->view('welcome_message');
}
}