Php 单击按钮以更改CodeIgniter中的视图
当用户访问我的页面时,他们会被带到一个主屏幕,该屏幕当前有一个标题和一个按钮。一个按钮是开始游戏,它应该重定向到一个有游戏板的视图。如何将该信息从按钮发送到控制器以访问新视图。 在我看来,这是一个按钮。该按钮应将信息发送到功能单击Php 单击按钮以更改CodeIgniter中的视图,php,codeigniter,Php,Codeigniter,当用户访问我的页面时,他们会被带到一个主屏幕,该屏幕当前有一个标题和一个按钮。一个按钮是开始游戏,它应该重定向到一个有游戏板的视图。如何将该信息从按钮发送到控制器以访问新视图。 在我看来,这是一个按钮。该按钮应将信息发送到功能单击 <form id="start" action="index.php/click" method="POST" > <input type="submit" name="start" value="startGame" /&g
<form id="start" action="index.php/click" method="POST" >
<input type="submit" name="start" value="startGame" />
</form>
我让它加载欢迎信息只是为了学习如何重定向。我的小组还没有完全建立游戏板页面试试看
function click()
{
$action = $_POST['start'];
if($action == 'startGame')
{
$this->load->view('welcome_message');
}
}
试试看
有几件事你需要改变。 1.尝试为控制器使用另一个名称,而不是index.php。例如test.php。我认为控制器名称不允许使用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');
}
}
}
这应该行得通。谢谢 有几件事你需要改变。 1.尝试为控制器使用另一个名称,而不是index.php。例如test.php。我认为控制器名称不允许使用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');
}
}
}
这应该行得通。谢谢
<form id="start" action="test/click" method="POST" >
<input type="submit" name="start" value="startGame" />
</form>