我正在使用codeignator开发库存管理,无法跟踪文件类型(入库/出库)。
在我的控制器中,我首先定义$fileT如下。
class Inventory extends CI_Controller
{
public $fileT='';
public function __construct()
{.....
当用户访问localhost.com/ci/index/stockin时,我希望将值(stockin)存储在$fileT,中
function index($fileType)
{
$this->fileT=$fileType;
用户输入要库存的产品后,应该访问localhost.com/ci/save_order。下面是我如何访问fileT的。但结果什么都不是。
public function save_order()
{
echo $this->fileT;
有人能帮忙吗?谢谢
在URL之间切换时,CodeIgniter甚至PHP都无法记住保存在对象中的值。因此,如果我们希望我们的应用程序在不同url之间移动时记住值,我们需要将它们保存在php$_SESSION or $_COOKIE
中。让我们更改一下您的代码:
localhost.com/ci/index/stockin
function index($fileType)
{
$_SESSION['fileType'] = $fileType;
}
localhost.com/ci/save_order
public function save_order()
{
if (isset($_SESSION['fileType']))
echo $_SESSION['fileType'];
}
然后,您可以在使用unset($_SESSION['fileType'])
成功保存订单后清除您的$_SESSION["文件类型"]。