cakephp - Global variable change to null after calling an action in controller -


i want call delete action, global variable sets null. controller:

app::uses('appcontroller', 'controller');  class whitelistcontroller extends appcontroller { public $helpers = array('html', 'form');  private $deletes;   public function index() {     if ($this->request->is('post'))     {          $whitelist = $_post['data']['whitelist']['stylecodes'];         if($whitelist == "")             return $this->session->setflash('you did not enter stylecodes. if send this, delete shoes website.');           $whitelist = preg_replace('/\s+/', '', $whitelist);         $whitelist = explode(",", $whitelist);           $url = 'http://fonda.vps.***********/product_import_json_all_published_products';         $ch = curl_init($url);         curl_setopt( $ch, curlopt_post, 1);         curl_setopt( $ch, curlopt_followlocation, 1);         curl_setopt( $ch, curlopt_header, 0);         curl_setopt( $ch, curlopt_returntransfer, 1);         $all = curl_exec($ch);         $all = json_decode($all, true);         print_r($all);          $this->deletes = array_diff($all, $whitelist);          if($this->deletes == $all)             return $this->session->setflash('it seems entered wrong data, delete of shoes website.');           $this->deletes = array_values($this->deletes);         pr($this->deletes);          $this->set('delete', $this->deletes);         $this->render('delete');     }  }  public function delete() {     if($this->request->is('post'))     {       }else{          $url = 'http://fonda.vps.*******/product_import_json_remove';         $myvars = 'products=' . json_encode($this->deletes);         print_r();          pr($myvars);         $ch = curl_init($url);         curl_setopt($ch, curlopt_post, 1);         curl_setopt($ch, curlopt_postfields, $myvars);         curl_setopt($ch, curlopt_followlocation, 1);         curl_setopt($ch, curlopt_header, 0);         curl_setopt($ch, curlopt_returntransfer, 1);         $response = curl_exec($ch);         $response = json_decode($response, true);          pr($response);              $removed = count($response['removed']);         $skipped = count($response['skipped']);          $string = $removed . " shoe(s) removed , " . $skipped . " shoe(s) skipped.";         $this->session->setflash($string);          if (count($response['error']) != 0) {             $string = "";             echo " ";             foreach ($response['error'] $key => $value) {                 $string .= $key . ": " . $value;                 $string .= "\n";             }             $this->session->setflash('error found in following shoe(s): ' . $string);         }          return $this->redirect(array( 'action' => 'index'));      } }   } 

$this->deletes gets null after calling delete() view.

i don't see changes deletes value.

what problem?

i think figured out. removed global variable, , put local variable session in first action:

$this->session->write('deletes', $delete); 

and read in second action this:

$delete = $this->session->read('deletes'); 

so work $delete in second action.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -