Yii: How to create yii application object in another php application? - php

I want to use Yii functions in another open source project (moodle, joomla, ...) So I can benefit Yii powerful models.
I put following code in one of the files (ROOT/course/edit.php):
$yii = dirname(__FILE__) . '/../mws/framework/yii.php';
$config = dirname(__FILE__) . '/../mws/protected/config/main.php';
defined('YII_DEBUG') or define('YII_DEBUG', TRUE);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);
require_once($yii);
Yii::createWebApplication($config);
But I get following error:
PHP warning include(edit.php.php) [function.include]: failed to open stream:
No such file or directory
D:\WAMP\www\millms\mws\framework\YiiBase.php(427) 415
{ 416 include($classFile); 417
if(YII_DEBUG && basename(realpath($classFile))!==$className.'.php')
418 throw new
CException(Yii::t('yii','Class name "{class}" does not match class
file "{file}".', array( 419
'{class}'=>$className, 420
'{file}'=>$classFile, 421 )));
422 break; 423
} 424 } 425 } 426
else 427 include($className.'.php'); 428
} 429 else // class name with namespace in PHP 5.3
430 { 431
$namespace=str_replace('\','.',ltrim($className,'\')); 432
if(($path=self::getPathOfAlias($namespace))!==false) 433
include($path.'.php'); 434 else 435
return false; 436 } 437 return
class_exists($className,false) || interface_exists($className,false);
438 } 439 return true; Stack Trace
#0 + D:\WAMP\www\millms\mws\framework\YiiBase.php(427):
YiiBase::autoload() #1 unknown(0):
YiiBase::autoload("edit.php") #2 unknown(0):
spl_autoload_call("edit.php") #3 –
D:\WAMP\www\millms\lib\formslib.php(831): is_a("edit.php",
"moodle_url") 826 static $formcounter = 1; 827
828 HTML_Common::HTML_Common($attributes); 829
$target = empty($target) ? array() : array('target' => $target);
830 $this->_formName = $formName; 831 if
(is_a($action, 'moodle_url')){ 832 $this->_pageparams
= $action->hidden_params_out(); 833 $action = $action->out(true); 834 } else { 835
$this->_pageparams = ''; 836 } #4 –
D:\WAMP\www\millms\lib\formslib.php(115):
MoodleQuickForm->MoodleQuickForm("course_edit_form", "post",
"edit.php", "", ...) 110 $action =
strip_querystring(qualified_me()); 111 } 112 113
$this->_formname = get_class($this); // '_form' suffix kept in order
to prevent collisions of form id and other element 114
$this->_customdata = $customdata; 115 $this->_form =& new
MoodleQuickForm($this->_formname, $method, $action, $target,
$attributes); 116 if (!$editable){ 117
$this->_form->hardFreeze(); 118 } 119
$this->set_upload_manager(new upload_manager()); 120 #5
– D:\WAMP\www\millms\course\edit.php(448):
moodleform->moodleform("edit.php", array("course" => null, "category"
=> stdClass)) 443 } 444 } 445 446 447 /// first create the form 448 $editform = new
course_edit_form('edit.php', compact('course', 'category')); 449
// now override defaults if course already exists 450 if
(!empty($course)) { 451 $course->enrolpassword =
$course->password; // we need some other name for password field
MDL-9929 452 $editform->set_data($course); 453 }
How I can Create A raw Yii Application Object?

Related

SMPP/PHP - SmppException Failed to read reply to command: 0x4 (php/smpp master)

Need pro help
Im trying to send sms to my smpp server using onlinecity/php-smpp lib Master.
Code:
<?php
require_once "smpp/smppclient.class.php";
require_once "smpp/gsmencoder.class.php";
require_once "smpp/sockettransport.class.php";
// Construct transport and client
$transport = new SocketTransport(array("my smpp server ip"),2775);
$transport->setSendTimeout(10000);
//$transport->setRecvTimeout(10000);
$smpp = new SmppClient($transport);
$smpp->debug = true;
$transport->debug = true;
// Open the connection
$transport->open();
$smpp->bindTransmitter("test user", "test pass");
// Optional connection specific overrides
//SmppClient::$sms_null_terminate_octetstrings = false;
//SmppClient::$csms_method = SmppClient::CSMS_PAYLOAD;
//SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH;
// Prepare message
$message = 'Hello world bla bla';
$encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
$from = new SmppAddress('SMPP Test',SMPP::TON_ALPHANUMERIC);
$to = new SmppAddress(4512345678,SMPP::TON_INTERNATIONAL,SMPP::NPI_E164);
// Send
$messageID = $smpp->sendSMS($from,$to,$encodedMessage);
// Close connection
$smpp->close();
?>
Browser response:
Fatal error: Uncaught SmppException: Failed to read reply to command: 0x4 in /home1/myproject/ems.myproject.com/smpp/smppclient.class.php:620
Stack trace:
#0 /home1/myproject/ems.myproject.com/smpp/smppclient.class.php(392): SmppClient->sendCommand(4, '\x00\x05\x00SMPP Test\x00\x01\x01...')
#1 /home1/myproject/ems.myproject.com/smpp/smppclient.class.php(340): SmppClient->submit_sm(Object(SmppAddress), Object(SmppAddress), 'Hello Voz bla b...', NULL, 0)
#2 /home1/myproject/ems.myproject.com/send_sms.php(35): SmppClient->sendSMS(Object(SmppAddress), Object(SmppAddress), 'Hello world bla b...')
#3 {main}
thrown in /home1/myproject/ems.myproject.com/smpp/smppclient.class.php on line 620
smppclient.class.php:
614 protected function sendCommand($id, $pduBody)
615 {
616 if (!$this->transport->isOpen()) return false;
617 $pdu = new SmppPdu($id, 0, $this->sequence_number, $pduBody);
618 $this->sendPDU($pdu);
619 $response=$this->readPDU_resp($this->sequence_number, $pdu->id);
620 if ($response === false) throw new SmppException('Failed to read reply to command: 0x'.dechex($id));
621
622 if ($response->status != SMPP::ESME_ROK) throw new SmppException(SMPP::getStatusMessage($response->status), $response->status);
623
624 $this->sequence_number++;
625
626 // Reached max sequence number, spec does not state what happens now, so we re-connect
627 if ($this->sequence_number >= 0x7FFFFFFF) {
628 $this->reconnect();
629 }
630
631 return $response;
Note:
PHP 7.4 on Apache
Anyone please help to identify what im doing wrong.
*** Please advice if there any better updated lib for php/smpp

how to fix Issue with codeigniter 4 after pushing to live server

After building my website on localhost it works fine but when I launched it to a live server, the homepage displays, and few other pages as others couldn't. Please can someone help me out?
I got this error
rewind($this->fileHandle);
207 }
208
209 $session_data = '';
210 clearstatcache(); // Address https://github.com/codeigniter4/CodeIgniter4/issues/2056
211 for ($read = 0, $length = filesize($this->filePath . $sessionID); $read < $length; $read += strlen($buffer))
212 {
213 if (($buffer = fread($this->fileHandle, $length - $read)) === false)
214 {
215 break;
216 }
217
218 $session_data .= $buffer;
219 }
and this
Fatal error: Uncaught ErrorException: Unknown: Cannot call session save handler in a recursive manner in Unknown:0 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Unknown: Cannot...', 'Unknown', 0, NULL) #1 {main} thrown in Unknown on line 0

PHP MAILER Warning: trim() expects parameter 1 to be string

am using phpmailer to send mail, which is sending mail but i keep getting this error, any help is appreciated,
Warning: trim() expects parameter 1 to be string, object given in
........../mail/class.phpmailer.php on line
773
Warning: trim() expects parameter 1 to be string, object given in
........../mail/class.phpmailer.php on line
773
Warning: trim() expects parameter 1 to be string, object given in
........../mail/class.phpmailer.php on line
773
here is line 771 downwards
771 protected function addOrEnqueueAnAddress($kind, $address, $name)
772 {
773 $address = trim($address);
774 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
775 if (($pos = strrpos($address, '#')) === false) {
776 // At-sign is misssing.
777 $error_message = $this->lang('invalid_address') . " (addAnAddress $kind): $address";
778 $this->setError($error_message);
779 $this->edebug($error_message);
780 if ($this->exceptions) {
781 throw new phpmailerException($error_message);
782 }
783 return false;
784 }

Laravel's Storage::makeDirectory returns mkdir: invalid argument

So I'm trying to create a new directory in C:/..../public/videos folder when somebody uploads a video, using the following code:
if ($request->hasFile('video')) {
$newDir = public_path('videos\\' . $story->story_id);
Storage::makeDirectory( $newDir, 0755, true);
$request->file('video')->move($newDir);
}
But I get this error:
ErrorException in Local.php line 350: mkdir(): Invalid argument in
Local.php line 350 at HandleExceptions->handleError('2', 'mkdir():
Invalid argument',
'C:\xampp\htdocs\qanda2\vendor\league\flysystem\src\Adapter\Local.php',
'350', array('dirname' => 'C:\xampp\htdocs\qanda2\public\videos\31',
'config' => object(Config), 'location' =>
'C:\xampp\htdocs\qanda2\storage\app\C:\xampp\htdocs\qanda2\public\videos\31',
'umask' => '0', 'visibility' => 'public')) at
mkdir('C:\xampp\htdocs\qanda2\storage\app\C:\xampp\htdocs\qanda2\public\videos\31',
'493', true) in Local.php line 350 at
Local->createDir('C:\xampp\htdocs\qanda2\public\videos\31',
object(Config)) in Filesystem.php line 259 at
Filesystem->createDir('C:\xampp\htdocs\qanda2\public\videos\31') in
FilesystemAdapter.php line 276
It seems like makeDirectory automatically adds C:\xampp\htdocs\qanda2\storage\app\ in front of my path.
Is there any workaround for this? I've been struggling with this for a while now and I can't find anything about this issue.
To create a directory, you should use File, like this:
if ($request->hasFile('video')) {
$newDir = public_path('videos\\' . $story->story_id);
File::makeDirectory( $newDir, 0755, true);
$request->file('video')->move($newDir);
}

getting error of soap while using shipping validation

I am using ValidateShipment.php from purolator.com . I included all the wsdl files and included product key and password . But still getting error(s).
soap is already enabled.
you can see error here
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 64
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 71
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 75
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 82
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 90
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 95
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 99
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 101
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 106
Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in /home/bandito/public_html/ValidateShipment.php:110 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://webserv...', 'http://purolato...', 1, 0) #1 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->__call('ValidateShipmen...', Array) #2 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->ValidateShipment(Object(stdClass)) #3 {main} thrown in /home/bandito/public_html/ValidateShipment.php on line 110
and here is my php code-:
define("PRODUCTION_KEY", "**********************");
define("PRODUCTION_PASS", "***********");
define("BILLING_ACCOUNT", "**********");
define("REGISTERED_ACCOUNT", "**********");
function createPWSSOAPClient()
{
$client = new SoapClient( "wsdl/ShippingService.wsdl",
array (
'trace' => true,
'location' => "https://webservices.purolator.com/PWS/V1/Shipping/ShippingService.asmx",
'uri' => "http://purolator.com/pws/datatypes/v1",
'login' => PRODUCTION_KEY,
'password' => PRODUCTION_PASS
)
);
//Define the SOAP Envelope Headers
$headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1',
'RequestContext',
array (
'Version' => '1.4',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Rating Example'
)
);
//Apply the SOAP Header to your client
$client->__setSoapHeaders($headers);
return $client;
}
/*********************************************************************************
Validate Shipment Example(s)
EXAMPLE 01:
1 piece shipment, 10lbs, Purolator Express Service on a Thermal 4x6 Label
*********************************************************************************/
//Create a SOAP Client for Example 01
$client = createPWSSOAPClient();
//Populate the Origin Information
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
$request->Shipment->SenderInformation->Address->StreetNumber = "1234";
$request->Shipment->SenderInformation->Address->StreetName = "Main Street";
$request->Shipment->SenderInformation->Address->City = "Mississauga";
$request->Shipment->SenderInformation->Address->Province = "ON";
$request->Shipment->SenderInformation->Address->Country = "CA";
$request->Shipment->SenderInformation->Address->PostalCode = "L4W5M8";
$request->Shipment->SenderInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->SenderInformation->Address->PhoneNumber->AreaCode = "905";
$request->Shipment->SenderInformation->Address->PhoneNumber->Phone = "5555555";
//Populate the Desination Information
$request->Shipment->ReceiverInformation->Address->Name = "Aaron Summer";
$request->Shipment->ReceiverInformation->Address->StreetNumber = "2245";
$request->Shipment->ReceiverInformation->Address->StreetName = "Douglas Road";
$request->Shipment->ReceiverInformation->Address->City = "Burnaby";
$request->Shipment->ReceiverInformation->Address->Province = "BC";
request->Shipment->ReceiverInformation->Address->Country = "CA";
$request->Shipment->ReceiverInformation->Address->PostalCode = "V5C5A9";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->AreaCode = "604";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->Phone = "2982181";
//Future Dated Shipments - YYYY-MM-DD format
$request->Shipment->ShipmentDate = "YOUR_SHIPMENT_DATE_HERE";
//Populate the Package Information
$request->Shipment->PackageInformation->TotalWeight->Value = "10";
$request->Shipment->PackageInformation->TotalWeight->WeightUnit = "lb";
$request->Shipment->PackageInformation->TotalPieces = "1";
$request->Shipment->PackageInformation->ServiceID = "PurolatorExpress";
//Populate the Payment Information
$request->Shipment->PaymentInformation->PaymentType = "Sender";
$request->Shipment->PaymentInformation->BillingAccountNumber = BILLING_ACCOUNT;
$request->Shipment->PaymentInformation->RegisteredAccountNumber = REGISTERED_ACCOUNT;
//Populate the Pickup Information
$request->Shipment->PickupInformation->PickupType = "DropOff";
//Shipment Reference
$request->Shipment->TrackingReferenceInformation->Reference1 = "Reference For Shipment";
//Define the Shipment Document Type
$request->PrinterType = "Thermal";
//Define OptionsInformation
$request->OptionsInformation->Options->OptionIDValuePair->ID = "residentialsignaturedomestic";
$request->OptionsInformation->Options->OptionIDValuePair->Value = "true";
//Execute the request and capture the response
$response = $client->ValidateShipment($request);
print_r($response);
The $request class isn't declared. PHP is guessing it's an object and declaring it.
Try:
$request = new stdClass;
$request->Shipment = new stdClass;
$request->Shipment->ReceiverInformatio = new stdClass;
etc.
Place before the $request list starts.
//Populate the Origin Information
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
Replace this line
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
with
#$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";

Categories