如何访问一个变量被另一个函数来设置一个PHP类? codeigniter [英] How to access a variable in a PHP class that is set by another function? Codeigniter

查看:114
本文介绍了如何访问一个变量被另一个函数来设置一个PHP类? codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有这个code在PHP中使用codeigniter框架,我似乎无法让我的周围类变量头在这个code似乎C ++完全不同。

I have this code here in PHP using Codeigniter framework, I can't seem to get my head around class variables in this code seems completely different to C++.

我想知道我怎么可以在一个类(功能)方法得到一个局部变量的另一个类方法。

I was wondering how I can get a local variable in one class (function) method to another class method.

但不是将它们作为变量,我必须使用重定向功能,而不是它不能采取变量。

But not passing them as variables as I have to use a redirect function instead which cannot take variables.

我想有访问该变量的 $ RECORD_ID 后,我试图使其公开等不喜欢它。

The variable I want to have accessible is $record_id , i tried making it public etc does not like it.

类提交扩展是CI_Controller
{

class Submit extends CI_Controller {

function send_data()
{
        $record_id = $this->submit_model->create_record($completedstaffrows, $completedeventrows);

                        if ($record_id == FALSE)
                        {
                            echo "Failed to add to database";
                        }

                        //Submittal to database was successful
                        else
                        {

                            redirect('submit/success');
                        }
                        return;
                    }

这是我想有机会获得该函数在 $ RECORD_ID

This is the function that I want to have access the $record_id

public function success()
{

$page['page'] = 'success';
$page['record'] = $record_id;
$this->load->view('template', $page );


}

记住 - 因为我需要使用重定向,使我的网址不会搞砸我不能通过这是一个变量的其他职能。谢谢

Remember - I cannot pass this as a variable to the other function as I need to use a redirect so that my URL will not screw up. Thanks

干杯!

推荐答案

使用codeigniter的称为微小Flashdata功能,它可以让你有请求之间temorarily存储数据。

use codeigniter's tiny feature called Flashdata which allows you to have temorarily store data between requests.

所以你的code将

function send data{
$this->session->set_flashdata('recordid', $recordid);
}

function success{
 $recordid =  $this->session->flashdata('recordid');
}

明白了吗?

这篇关于如何访问一个变量被另一个函数来设置一个PHP类? codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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