如何在同一个类的另一个函数中使用一个函数的变量-Codeigniter [英] How to use a variable of a function in another function of same class -Codeigniter

查看:63
本文介绍了如何在同一个类的另一个函数中使用一个函数的变量-Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 $ Id 的值从 firstFunction 分配给 secondFunction 中的变量 $ temp .

I want to assign the value of $Id from firstFunction to the variable $temp in secondFunction.

public function firstFunction()
{
    $Id = $_POST['quizID_click'];
}


public function secondFunction()
{
    $temp = ------;
}

请让我知道如何在 secondFunction

推荐答案

如果我正确理解您只想在Controller函数内部传递一个变量,则可以通过以下操作来实现:

If i understand correctly you want to pass only a variable inside the Controller functions, You can do it by throwing a flash like this:

    public function firstFunction()
    {
        $this->load->library('session');
        $Id = $_POST['quizID_click'];
        $this->session->set_flashdata('item', $Id);
    }


    public function secondFunction()
    {
        $myVar = $this->session->flashdata('item');
    }

基本上,您可以将变量值临时保存为flashdata,并赋予它'item''item'可以是任何值.然后第二个控制器查找此flashdata并将其分配给 $ myVar

Basically you temporary save the variable value as flashdata giving it a 'item' value 'item' can be anything. then the second controller looks for this flashdata and asigns it to $myVar

这篇关于如何在同一个类的另一个函数中使用一个函数的变量-Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆