I’m trying to figure out what is going on below:
public function serviceAction(){
$config = Zend_Registry::get('config');
$client = new Zend_Http_Client();
$client->setAuth($config['api']['username'],$config['api']['password']);
$service = new Krixton_JsonRpc_Client($config['api']['endpoint'], $client);
switch($this->_getParam('task'))
{
case 'test':
if(!this->getParam('newsletter_id')){
$this->_helper->json(array('sent'=>false,'error'=>'Newsletter ID is invalid, must be numeric'));
return;
}
$request = $service->call('newsletter.send', array($this->_getParam('newsletter_id'),false));
$this->_helper->json($request->result));
break;
}
}
What I’m trying to find out is how does
`Zend_Registry::get('config')`, $client->setAuth and $service->call`
works?
I understand _getParam('task') is a method to get get or post variables but not sure about the others. I had a look through some Zend documentations but if someone could help me out that would be appreciated!
Two things are happening there, the first one is
Zend_Registry.get()allow you to get a value previously registered in the registry viaZend_Registry::set('key', $value). Usually, ‘config’ is your application configuration, which is the application.ini file.basically, you would register config using this bootstrap method:
The second ones are nothing else than methods of
Zend_Http_Client.setAuth()is used to set a basic HTTP authentification, andcall()is an internal method of your objectKrixton_JsonRpc_Client.If you’re trying to understand deep down how does these methods work, you should read the man first (especially Zend_registry and Zend_Http_Client pages) and then read carefully the source code.