开发者

CodeIgniter, Accessing class property after page reloads, is it possible?

开发者 https://www.devze.com 2023-03-08 08:49 出处:网络
I have a CI page that will load to a div in view file, using jQuery. Using switch(page_parameter), I control what is showing from the page.

I have a CI page that will load to a div in view file, using jQuery. Using switch(page_parameter), I control what is showing from the page.

When I call the page for 3rd time, I set a value to the class array. But when I call the 4th time, the array become empty.

I was wondering, is it actually possible to use the class property to store value that can be used after page re-access? Or something missing in my head? I know that using session is not a good idea, since the real array is a big chunk of serialized xml.

Here's my code:

class MyClass extends MY_Controller
{
    public static $pitems = array();

    function Hotel(){
        parent::MY_Controller();
    }

   function new_campaign(){
        $params = $this->uri->uri_to_assoc();
        switch($params['step']){
             case '3' : self::$pitems = array("test","another"); //here the class array was set successfully
                        $this->load->view('viewer');
                        break;
             case '4' : print_r(self::$pitems); //here the array is empty
                        break;

        }
   }

In the viewer page, there's a call to the page:

   <a href="myclass/new_campai开发者_如何学Cgn/step/4">Next page</a>

Same issue also with $this-> What am i missing here? Thanks in advance~

edit: I saw a script that has similar scenario. it successfully reused the variable set in the constructor, instead of treating it as a class variable. i'll look thorough to confirm this, but for now, i'll close this thread. Thanks Chris for sharing.


Im not really sure what your trying to do but I have users jQuery post()/get()/ajax() many of times in CI and have had no problems. So despite not knowing or understanding what your trying to do. I thought I'd at least say I know loading data without refresh in CI through something like jQuery isn't an issue. Example on system I built on CI had a twitter like feed of tweets where jQuery on a timer was polling for new data and coming back with it each time accordingly if something new was to be shown.

0

精彩评论

暂无评论...
验证码 换一张
取 消