Well if it were me i would only be using that Geocode controller to
wrap the functionality of a model(s) that actually handle making the API
request and returning the output. So itd be something like this
// in Default_GeocodeController
public function addressAction(){
// do whtever you need to with request params and what not;
$gcode = new My_GoogleApi_Geocode();
$latlong = $gecode->getLatLng($args);
$this->view->latlng = Zend_Json::encode($latlng);
// do stuff for json headers and render
}
// in Default_AddressController
public function createAddress()
{
$addressStr = $this->getRequest()->getParam('address');
$address = new Default_Model_Address();
$address->setAddress($address);
$gcode = new My_GoogleApi_Geocode();
$latlng = $gecode->getLatLng($args);
if($latlong)
{
$address->setLatitude($latlng['lat']);
$address->setLongitude($latlng['lng']);
}
// set other stuff like state/prov, country, zip, etc..
$address->save();
$this->view->address = $address;
}
I would then use a special getter/mutator to get the lat/lng as JSON,
PHP Array, etc. directly from my model for other use cases.
tony stamp wrote:
Thanks for replying.
The action view helper isn't really what i'm after - that would assume the
address needs to be assigned to the view, so the view helper can make the
lookup. What i'm after is a seperate request to obtain the addresses
geocodes before it is inserted into the db, so all the information is
complete.
I rustled up something last night using the ActionStack controller helper:
from within my AddressController, before the address is inserted:
$response = $this->_helper->actionStack('address',
'Geocode',
'default',
array('address'=> $addressQueryString));
...which calls...
class GeocodeController extends Zend_Controller_Action
{
public function addressAction(){
$viewRenderer =
Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$viewRenderer->setNoRender(true);
$request = $this->getRequest();
echo $request->getParam('address');
}
}
So far i'm still reading up how to return a json response, but i'm also
figuring out how the actionstack really operates - it seems to discontinue
the current request and initiate a new one, instead of firing a kindof
subrequest - in fact i'm not even sure that's possible, but i'll keep on
reading. In the meantime, any pointers would be appreciated :)