我SearchController
在Hotel模块中有一个控制器,在该控制器中有一个方法,如下所示。
public function searchAction()
{
// Code for search
// want to call getlatlng method
}
现在我DistanceController
在同一模块中创建了一个新的控制器,并getlatlng
在距离控制器中创建了一个方法。我的getlatlng方法是这样的。
public function getlatlng()
{
$location = $_REQUEST['lat'].','.$_REQUEST['lng'];
return $location;
}
现在我想getlatlng
在searchAction
方法中调用一个方法。返回当前位置的纬度和经度。我使用post或get将纬度和经度传递给getlatlng函数。
那么如何在searchAction
方法中调用getlatlng方法呢?
您可以这样调用,如果您使用的是ZF版本1.x:
class SearchController extends Zend_Controller_Action
{
public function searchAction() {
echo "search_action_from_SearchController";
require_once ('DistanceController.php');
$distanceCtrl = new DistanceController($this->_request, $this->_response);
$distanceCtrl->xyzAction();
die;
}
}
class DistanceController extends Zend_Controller_Action
{
public function getlatlng() {
echo "getlatlng_from_DistanceController";
die;
}
}
输出:
URL: http://www.example.com/search/search
search_action_from_SearchController
getlatlng_from_DistanceController
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句