从php函数中的另一个目录运行php文件

时间:2015-05-13 05:52:05

标签: php magento

用户选择" 已接受"从下拉菜单中单击提交按钮,之后 test.php 这些路径加上下面给出的函数必须执行。 我怎么能这样做?

路径:

/var/www/html/demo/courier/test.php

以下是功能:

  if($testcodPayment->getMethodInstance()->getTitle() == 'Cash On Delivery' && $status == $statusAccepted && ($checkTrack12[0]['number']=='') && $selectCourier == 'couriername'){

include '/var/www/html/demo/courier/test.php' ;

            $awbNumbercouriername = $hlp->couriernameawbgenerate('couriername',$id);
            $title = Mage::getStoreConfig('carriers/'.$method[0].'/title', $store);
                        $track = Mage::getModel('sales/order_shipment_track')
                            ->setNumber($awbNumbercouriername)
                            ->setCarrierCode($method[0])
                        ->setCourierName('couriername')
                            ->setTitle('couriername');
             $shipment->addTrack($track);
             Mage::helper('shipmenty')->addShipmentComment(
                        $shipment,
                        $this->__('%s addeddd tracking ID %s', $vendor->getVendorName(), $awbNumbercouriername)



                    );

        $session->addSuccess($this->__('Tracking ID has been added. Please take three printouts of each manifest and keep one copy of airway bill signed by courier boy with you as proof of pick up.  '));
        $highlight['tracking'] = true;
        $customerMessage = 'Your order has been shipped. Tracking Details.Shipment#: '.$_shipmentId.' , Track Number: '.$awbNumberFedex.'Courier Partner : www.fedex.com - Craftsvilla.com (Customercare email: customercare@craftsvilla.com)';
        $_customerSmsUrl = $_smsServerUrl."username=".$_smsUserName."&password=".$_smsPassowrd."&type=0&dlr=0&destination=".$customerTelephone."&source=".$_smsSource."&message=".urlencode($customerMessage);
        $parse_url = file($_customerSmsUrl);
        $shipment->save();



    }

2 个答案:

答案 0 :(得分:0)

在你的函数中使用require()命令,它应该可以解决问题。

require('/var/www/html/demo/courier/test.php');

答案 1 :(得分:0)

您可以使用includerequire命令。

假设您想在功能之前执行test.php

然后,使用

<?php

include '/var/www/html/demo/courier/test.php';
yourFnction();

?>

您也可以使用require。不同之处在于,如果找不到该文件,则脚本执行将死亡。然而,如果您使用include,即使找不到该文件,脚本也会继续执行yourFunction()

<?php

include '/var/www/html/demo/courier/test.php';
yourFunction();

?>

您甚至可以在功能

中调用include
<?php

function yourFunction(){

echo "a";
include '/var/www/html/demo/courier/test.php';
echo "b";

}

?>