magento - Defining and working with global object for codeigniter controller -


Hello I'm just working with Magento Soap Clint and I am creating a lot of functions within a controller And that's why I want to set $ client and $ session_id in global form.

This is my code -

    

// Stop all error reporting

  error_reporting (0);   

// with SOAP client

  is required APPPATH.'third_party / client / soap_clinet.php ';   

// class API

  class extends your CI_Controller {  

// public variable

  public $ variable = "tree"; // work fine   

// Define the client object as the following error is also made.

  public $ client = new SoapClient ('http: // localhost /mystore/index.php/api/?wsdl'); Public $ session_id; Public function _ composition () {origin: _ creation (); } Function index () {$ data ['title'] = "SOAP"; $ Data ['title'] = "showing magteo soap connectivia"; $ This- & gt; Load-> View ('upview', $ data); }   

// I need help for this function

  function login () {{$ this-> session_id = $ this- & gt; - & gt; Login ('fmniloy', 'abc123'); Resonance 'full connection: session id ='. $ This- & gt; Session_id; } Catch (easyfault $ mistake) {echo 'defect code:' $ fault- & gt; Miscreated '& Lt; Br / & gt; '; Reason 'Reason for Mistake:'. $ Fault-> Wrong string; }} // login function tree () ends {// it is printing global $ variable successfully $$ - this variable; }}? & Gt; Finally, I found a solution first to declare something as public. It is not possible that we can pass $ client object and $ session_id to other functions. The solution is in the form of the following.  
  & lt ;? Php   

// Close all error reporting error _ Reporting (0); // SOAP Client with

  is required APPPATH.'third_party / client / soap_clinet.php ';   

// class API

  Expands class API CI_Controller {// public variable public $ remote_server = "http: // localhost / mystore / Index.php? / API / wsdl "; Public $ username = "fmniloy"; Public $ password = "ABC 123"; Public function _ composition () {origin: _ creation (); } Function index () {$ data ['title'] = "SOAP"; $ Data ['title'] = "showing magteo soap connectivia"; $ This- & gt; Load-> View ('upview', $ data); } // Login to Login Server Function Login () {// Client service to login $ client = new SOAP client ($-> this-> remote_server); Try {// webservice is full of user name and passwd $ session_id = $ client- & gt; Login ($ this- & gt; username, $ this- & gt; password); // resonance 'connection complete: session id =' $ session_id; } Catch (easyfault $ mistake) {echo 'defect code:' $ fault- & gt; Miscreated '& Lt; Br / & gt; '; Reason 'Reason for Mistake:'. $ Fault-> Wrong string; }   

// Input a client object and $ session_id into an array $ soap_vars = array ($ client, $ session_id); // Return value to use in other functions $ SOAP_vars;

 }   

// login ends

  function tree () {$ soap_vars = $ this- & Gt; Login (); $ Result = $ soap_vers [0] - & gt; Call ($ sop_vers [1], 'catalog_marktree'); Echo & lt; / Br & gt; & Lt; / Br & gt; & Lt; / Br & gt; Tree tree: '; Var_dump ($ result); }}? & Gt;    

Comments

Popular posts from this blog

c# - Textbox not clickable but editable -

Matlab transpose a table vector -

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -