When I try saving an item's to my database I get
Method Clients::__toString() must return a string value
Current code
$name = Input::get('email');
$client = Input::get('client');
$website = Input::get('website');
$userassign = Input::get('userassign');
$client = new Clients();
$client->name = $name;
$client->client = $client;
$client->website = $website;
$client->parent = $userassign;
$client->save();
Any ideas?
You're redefining $client.
$name = Input::get('email');
$clientInput = Input::get('client');
$website = Input::get('website');
$userassign = Input::get('userassign');
$client = new Clients();
$client->name = $name;
$client->client = $clientInput; //Here was your problem
$client->website = $website;
$client->parent = $userassign;
$client->save();
Related
i was used the sms API in my Bluehost hosting. when i was run the code it shown like
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://smeapps.mobitel.lk:8585/EnterpriseSMSV3/EnterpriseSMSWS?wsdl' : failed to load external entity "http://smeapps.mobitel.lk:8585/EnterpriseSMSV3/EnterpriseSMSWS?wsdl" in /storage/ssd4/825/11729825/public_html/sms/sms_backend.php:58 Stack trace: #0 /storage/ssd4/825/11729825/public_html/sms/sms_backend.php(58): SoapClient->SoapClient('http://smeapps....') #1 /storage/ssd4/825/11729825/public_html/sms/sms_backend.php(101): getClient() #2 /storage/ssd4/825/11729825/public_html/sms/sms_backend.php(27): createSession('', 'esyyyyy', 'xxxx', '') #3 {main} thrown in /storage/ssd4/825/11729825/public_html/sms/sms_backend.php on line 58
here this is my code
<?php
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
//$alias = $_REQUEST['alias'];
$message = $_REQUEST['message'];
$number = $_REQUEST['numbers'];
$session=createSession('',$username,$password,'');
sendMessages($session,'XXXX',$message,$number,0); // 1 for promotional messages, 0 for normal message
closeSession($session);
$session=createSession('',$username,$password,'');
getMessagesFromShortCode($session,"shortcode");
getMessagesFromLongNumber($session,"longnum");
closeSession($session);
//create soap client
function getClient()
{
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("http://smeapps.mobitel.lk:8585/EnterpriseSMSV3/EnterpriseSMSWS?wsdl");
return $client;
}
//serviceTest
function serviceTest($id,$username,$password,$customer)
{
$client = getClient();
$user = new stdClass();
$user->id = '';
$user->username = $username;
$user->password = $password;
$user->customer = '';
$serviceTest = new stdClass();
$serviceTest->arg0 = $user;
return $client->serviceTest($serviceTest);
}
//create session
function createSession($id,$username,$password,$customer)
{
$client = getClient();
$user = new stdClass();
$user->id = $id;
$user->username = $username;
$user->password = $password;
$user->customer = $customer;
$createSession = new stdClass();
$createSession->user = $user;
$createSessionResponse = new stdClass();
$createSessionResponse = $client->createSession($createSession);
return $createSessionResponse->return;
}
//check if session is valid
function isSession($session)
{
$client = getClient();
$isSession = new stdClass();
$isSession->session = $session;
$isSessionResponse = new stdClass();
$isSessionResponse = $client->isSession($isSession);
return $isSessionResponse->return;
}
//send SMS to recipients
function sendMessages($session,$alias,$message,$recipients,$messageType)
{
$client=getClient();
$smsMessage= new stdClass();
$smsMessage->message=$message;
$smsMessage->messageId="";
$smsMessage->recipients=$recipients;
$smsMessage->retries="";
$smsMessage->sender=$alias;
$smsMessage->messageType=$messageType;
$smsMessage->sequenceNum="";
$smsMessage->status="";
$smsMessage->time="";
$smsMessage->type="";
$smsMessage->user="";
$sendMessages = new stdClass();
$sendMessages->session = $session;
$sendMessages->smsMessage = $smsMessage;
$sendMessagesResponse = new stdClass();
$sendMessagesResponse = $client->sendMessages($sendMessages);
return $sendMessagesResponse->return;
}
//send Unicoded SMS to recipients
function sendMessagesMultiLang($session,$alias,$message,$recipients,$messageType)
{
$client=getClient();
$smsMessageMultiLang = new stdClass();
$smsMessageMultiLang->message=$message;
$smsMessageMultiLang->messageId="";
$smsMessageMultiLang->recipients=$recipients;
$smsMessageMultiLang->retries="";
$smsMessageMultiLang->sender=$alias;
$smsMessageMultiLang->messageType=$messageType;
$smsMessageMultiLang->sequenceNum="";
$smsMessageMultiLang->status="";
$smsMessageMultiLang->time="";
$smsMessageMultiLang->type="";
$smsMessageMultiLang->user="";
$sendMessagesMultiLang = new stdClass();
$sendMessagesMultiLang->session = $session;
$sendMessagesMultiLang->smsMessageMultiLang = $smsMessageMultiLang;
$sendMessagesMultiLangResponse = new stdClass();
$sendMessagesMultiLangResponse = $client->sendMessagesMultiLang($sendMessagesMultiLang);
return $sendMessagesMultiLangResponse->return;
}
//send Campaign SMS to recipients
function sendCampaignMessages($session,$alias,$message,$recipients,$datetime,$multilanguage,$messageType)
{
$client=getClient();
$smsCampaignMessage = new stdClass();
$smsCampaignMessage->message = $message;
$smsCampaignMessage->messageId = "";
$smsCampaignMessage->recipients = $recipients;
$smsCampaignMessage->retries = "";
$smsCampaignMessage->sender = $alias;
$smsCampaignMessage->messageType=$messageType;
$smsCampaignMessage->sequenceNum = "";
$smsCampaignMessage->status = "";
$smsCampaignMessage->time = $datetime;
$smsCampaignMessage->type = "";
$smsCampaignMessage->user = "";
$smsCampaignMessage->esmClass = $multilanguage;
$sendCampaignMessages=new stdClass();
$sendCampaignMessages->session=$session;
$sendCampaignMessages->smsCampaignMessage=$smsCampaignMessage;
$sendCampaignMessagesResponse = new stdClass();
$sendCampaignMessagesResponse = $client->sendCampaignMessages($sendCampaignMessages);
return $sendCampaignMessagesResponse->return;
}
//renew session
function renewSession($session)
{
$client = getClient();
$renewSession = new stdClass();
$renewSession->session = $session;
$renewSessionResponse = new stdClass();
$renewSessionResponse = $client->renewSession($renewSession);
return $renewSessionResponse->return;
}
//close session
function closeSession($session)
{
$client = getClient();
$closeSession = new stdClass();
$closeSession->session = $session;
$client->closeSession($closeSession);
}
//retrieve messages from shortcode
function getMessagesFromShortCode($session,$shortCode)
{
$client = getClient();
$getMessagesFromShortCode = new stdClass();
$getMessagesFromShortCode->session = $session;
$getMessagesFromShortCode->shortcode = $shortCode;
$getMessagesFromShortcodeResponse = new stdClass();
$getMessagesFromShortcodeResponse->return = "";
$getMessagesFromShortcodeResponse = $client->getMessagesFromShortcode($getMessagesFromShortCode);
if(property_exists($getMessagesFromShortcodeResponse,'return'))
return $getMessagesFromShortcodeResponse->return;
else return NULL;
}
//retrieve delivery report
function getDeliveryReports($session,$alias)
{
$client = getClient();
$getDeliveryReports = new stdClass();
$getDeliveryReports->session = $session;
$getDeliveryReports->alias = $alias;
$getDeliveryReportsResponse = new stdClass();
$getDeliveryReportsResponse->return = "";
$getDeliveryReportsResponse = $client->getDeliveryReports($getDeliveryReports);
if(property_exists($getDeliveryReportsResponse,'return'))
return $getDeliveryReportsResponse->return;
else return NULL;
}
//retrieve messages from longnumber
function getMessagesFromLongNumber($session,$longNumber)
{
$client = getClient();
$getMessagesFromLongNumber = new stdClass();
$getMessagesFromLongNumber->session = $session;
$getMessagesFromLongNumber->longNumber=$longNumber;
$getMessagesFromLongNumberResponse = new stdClass();
$getmessagesFromLongNumberResponse->return = "";
$getMessagesFromLongNumberResponse = $client->getMessagesFromLongNumber($getMessagesFromLongNumber);
if(property_exists($getMessagesFromLongNumberResponse,'return'))
return $getMessagesFromLongNumberResponse->return;
else return NULL;
}
?>
this code works in Localhost very well... but in my hosting (Bluehost) it was shown fatal error like that.
can any one help me to resolve this error??
Thanks in advance
It turns out that you need to have the extension php_openssl enabled on your server for it to work.
You can do this yourself on most hosting services by going to your PHP settings -> look for the option php_openssl.dll or php_openssl and enable it.
If you have access to your php.ini file, you could look for the line that says extension=php_openssl.dll and if this has a ; at the start like this ;extension=php_openssl.dll, remove the ; from the start so it reads extension=php_openssl.dll.
This should solve it for you.
I am building chats pop up where one user will initiate conversation with another user.
In my initiatechat function i have the following error Call to undefined method stdClass::save().
Look at codes and find THIS SAVE FUNCTION ==>> the save() function that throw error.
If two users have already initiated conversation this error does not happen.
public function actionInitiatechat() {
if (isset($_POST)){
//$message = Myclass::checkPostvalue($_POST['message']) ? $_POST['message'] : "";
$senderId = Myclass::checkPostvalue($_POST['sender']) ? $_POST['sender'] : "";
$receiverId = Myclass::checkPostvalue($_POST['receiver']) ? $_POST['receiver'] : "";
$messageType = Myclass::checkPostvalue($_POST['messageType']) ? $_POST['messageType'] : "";
$sourceId = Myclass::checkPostvalue($_POST['sourceId']) ? $_POST['sourceId'] : "";
$timeUpdate = time();
$message = $_POST['message'];
$Products = Products::model()->findByPk($sourceId);
if(isset($Products) && $Products->approvedStatus == 0)
{
echo "error";
}
else
{
$criteria = new CDbCriteria;
$criteria->condition = "(user1 = '$senderId' AND user2 = '$receiverId') OR (user1 = '$receiverId' AND user2 = '$senderId')";
$chatModel = Chats::model()->find($criteria);
$encodeMsg = urlencode($message);
if (empty($chatModel)){
$newChat = new Chats();
$newChat->user1 = $senderId;
$newChat->user2 = $receiverId;
$newChat->lastMessage = $encodeMsg;
$newChat->lastToRead = $receiverId;
$newChat->lastContacted = $timeUpdate;
$newChat->save();
$criteria = new CDbCriteria;
$criteria->condition = "(user1 = '$senderId' AND user2 = '$receiverId') OR (user1 = '$receiverId' AND user2 = '$senderId')";
$chatModel = Chats::model()->find($criteria);
}
$chatModel->lastContacted = $timeUpdate;
if ($chatModel->user1 == $senderId){
$chatModel->lastToRead = $chatModel->user2;
}else{
$chatModel->lastToRead = $chatModel->user1;
}
$chatModel->lastMessage = $encodeMsg;
THIS SAVE FUNCTION ==>> $chatModel->save();
$messageModel = new Messages();
$messageModel->message = $encodeMsg;
$messageModel->messageType = $messageType;
$messageModel->senderId = $senderId;
$messageModel->sourceId = $sourceId;
$messageModel->chatId = $chatModel->chatId;
$messageModel->createdDate = $timeUpdate;
$messageModel->save();
}
echo "success";
}
}
else
{
echo "failed";
}
}
The statement below is presumably returning a "bare" object of type stdClass, which doesn't define a save() method, hence your error.
$chatModel = Chats::model()->find($criteria);
Run var_dump($chatModel); immediately after this statement and see what type of object you're getting.
I have seen the other examples here on StackOverflow but neither are working for me, my code creates an address line in NetSuite but the addr1, city, state and zip are empty, the default billing and shipping do show false or if I set it to true it shows true so that part is updating.. The response doesn't show any errors. Any ideas?
Here is my code:
$customer = new Customer();
$customer->internalId = 16;
$customer->firstName = 'Joe';
$customer->middleName = 'A';
$customer->lastName = 'Smith';
$customer->email = 'joe#email.com';
$address = new CustomerAddressBook();
$address->defaultShipping = false;
$address->defaultBilling = false;
$address->isResidential = true;
$address->addr1 = '123 Street';
$address->city = 'New York';
$address->zip = '12345';
$address->state = 'NY';
$addressBook = new CustomerAddressbookList();
$addressBook->addressbook = array($address);
$addressBook->replaceAll = false;
// add address to cutomer
$customer->addressbookList = $addressBook;
$request = new UpdateRequest();
$request->record = $customer;
$netsuiteService = new NetSuiteService();
$response = $netsuiteService->update($request);
$address = new Address();
$address->addr1 = '123 Street';
$address->city = 'New York';
$address->zip = '12345';
$address->state = 'NY';
$address_book = new CustomerAddressBook();
$address_book->defaultShipping = false;
$address_book->defaultBilling = false;
$address_book->isResidential = true;
$address_book->addressbookAddress = $address;
$address_book_list = new CustomerAddressbookList();
$address_book_list->addressbook = $address_book;
$address_book_list->replaceAll = false;
$customer = new Customer();
$customer->internalId = 16;
$customer->firstName = 'Joe';
$customer->middleName = 'A';
$customer->lastName = 'Smith';
$customer->email = 'joe#email.com';
$customer->addressbookList = $address_book_list;
$request = new UpdateRequest();
$request->record = $customer;
$netsuiteService = new NetSuiteService();
$response = $netsuiteService->update($request);
if (!$response->writeResponse->status->isSuccess) {
echo "UPDATE ERROR";
} else {
echo "UPDATE SUCCESS, id " . $response->writeResponse->baseRef->internalId;
}
I am trying to send message with activation code. I have an registration form. The forms sends data to the controller and the controller saves the data into database . But somehow it fails to grab the $user variable after saving data into profiles table.
Here is my controller:
DB::transaction(function() use($first_name,$last_name,$email,
$password,$address,$phone,$country_id,$state,$city,
$zip_code,$skype,$birth_date,$code){
//add info to user table
$user = new User;
$user->username = $email;
$user->password = $password;
$user->email = $email;
$user->first_name = $first_name;
$user->last_name = $last_name;
$user->active = 0;
$user->code = $code;
$user->save();
//Get the user ID ceated just now
$new_users = $new_user->id;
// add information to Profile table
$profile = new Profile;
$profile->user_id = $new_users;
$profile->phone = $phone;
$profile->address = $address;
$profile->country_id = 1;
$profile->state = $state;
$profile->skype = $skype;
$profile->city = $city;
$profile->zip_code = $zip_code;
$profile->birth_date = $birth_date;
$profile->timezone_id = 1;
$profile->save();
});//inside a transaction
if($user){
Mail::send('emails.welcome',
array('link'=> URL::route('account-activate', $code),'user'=>$user->first_name),
function($message) use ($user) {
$message->to($user->email , $user->user)->from('admin#spandango.net')->subject('Active your account !');
}
);
return Redirect::back()
->with('message' , 'Your account is created ! Please check you email to activate your account !'); }
return Redirect::to('/message');
I think my code is absolutely right. Can you please explain why it fails to define the $user variable ?
This is because of the scope of the $user variable. Define $user above DB::transaction(function() {});
Though defining
$user = false;
above
DB::transaction
might do the trick for now but I won't recommend it as a good practice the best solution would be to use the
Mail::send()
inside the Database transaction block and you might can improve your code as well and the above code should be
DB::transaction(function() use($first_name,$last_name,$email,
$password,$address,$phone,$country_id,$state,$city,
$zip_code,$skype,$birth_date,$code,$user){
//add info to user table
$user = new User;
$user->username = $email;
$user->password = $password;
$user->email = $email;
$user->first_name = $first_name;
$user->last_name = $last_name;
$user->active = 0;
$user->code = $code;
$user->save();
//Get the user ID ceated just now
$new_users = $new_user->id;
// add information to Profile table
$profile = new Profile;
$profile->user_id = $new_users;
$profile->phone = $phone;
$profile->address = $address;
$profile->country_id = 1;
$profile->state = $state;
$profile->skype = $skype;
$profile->city = $city;
$profile->zip_code = $zip_code;
$profile->birth_date = $birth_date;
$profile->timezone_id = 1;
$profile->save();
if( !$profile || !$user )
{
return Redirect::back()
->with('message' , 'Your account is created ! Please check you email to activate your account !');
} else {
// Else commit the queries
Mail::send('emails.welcome',
array('link'=> URL::route('account-activate', $code),'user'=>$user->first_name),
function($message) use ($user) {
$message->to($user->email , $user->user)->from('admin#spandango.net')->subject('Active your account !');
}
);
}
});//inside a transaction
That is because $user is inside that DB transaction block; it goes out of scope with the closing brace. Define it above the transaction
Solution
Copy & Replace above.
$user = false;
DB::transaction(function() use($first_name,$last_name,$email,
$password,$address,$phone,$country_id,$state,$city,
$zip_code,$skype,$birth_date,$code,$user){
//add info to user table
$user = new User;
$user->username = $email;
$user->password = $password;
$user->email = $email;
$user->first_name = $first_name;
$user->last_name = $last_name;
$user->active = 0;
$user->code = $code;
$user->save();
//Get the user ID ceated just now
$new_users = $new_user->id;
// add information to Profile table
$profile = new Profile;
$profile->user_id = $new_users;
$profile->phone = $phone;
$profile->address = $address;
$profile->country_id = 1;
$profile->state = $state;
$profile->skype = $skype;
$profile->city = $city;
$profile->zip_code = $zip_code;
$profile->birth_date = $birth_date;
$profile->timezone_id = 1;
$profile->save();
});//inside a transaction
if($user){
Mail::send('emails.welcome',
array('link'=> URL::route('account-activate', $code),'user'=>$user->first_name),
function($message) use ($user) {
$message->to($user->email , $user->user)->from('admin#spandango.net')->subject('Active your account !');
}
);
return Redirect::back()
->with('message' , 'Your account is created ! Please check you email to activate your account !'); }
return Redirect::to('/message');
I am trying to create an authentication plugin, but I am having problems when the user does not exist in the moodle database. Therefore I am trying to find a way to manually create a user.
I tried:
$user = new StdClass();
$user->username = $ucUser;
$user->auth = 'ucauth';
$user->firstname = "First";
$user->lastname = "Last";
$user->id = $DB->insert_record('user', $user);
But it didn't work... I got an insert error. What else do I need in the $user object?
User object should have the following values:
$user = new StdClass();
$user->auth = 'manual';
$user->confirmed = 1;
$user->mnethostid = 1;
$user->email = "email";
$user->username = "username";
$user->password = md5('password');
$user->lastname = "lastname";
$user->firstname = "firstname";
$user->id = $DB->insert_record('user', $user);
Please try this.
Well, I recommend you to use authenticate_user_login($username, null) this is going to give you an empty user, wich you can complete later on in the proccess. Then you can use complete_user_login($user); and if you want to send the user to the edit page something like
if (user_not_fully_set_up($USER)) {
$urltogo = $CFG->wwwroot.'/user/edit.php';
}else{
$urltogo = $CFG->wwwroot.'/';
}
redirect($urltogo);
I don't know exactly what are you trying to achieve. But I've made a plugin to connect with an external web service and it took me a while to figure out how to do it properly. I'm able to help you with anything you need.
There are some values that needs to be setted when creating a user manually. I was facing the same situation and ended up with this solution:
global $DB;
$user = new StdClass();
$user->email = strtolower('someemail'); //MOODLE requires lowercase
$user->username = strtolower('someusername');//MOODLE requires lowercase
$user->password = hash_internal_user_password('somepassword');
$user->lastname = 'somelastname';
$user->firstname = 'somename';
// These values are required.
// Default values are stored in moodle config files but... this is easier.
$user->auth = 'manual';
$user->confirmed = 1;
$user->mnethostid = 1;
$user->country = 'ES'; //Or another country
$user->lang = 'es'; //Or another country
$user->timecreated = time();
$user->maildisplay= 0;
$user->id = $DB->insert_record('user', $user); // returns new userid
If you prefer, you can retrieve the whole user's data:
$lastid = $DB->insert_record('user', $user);
$user2 = get_complete_user_data('id', $lastid);