Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm new in android, I want to send My Drupal 7 content to Android. I can just send a $Variuable to android in this PHP webservice. How can I do that?
In android you have to create a async task in order to communicate with the server. Than you can send and receive variables from php script. ( you need to encode your variables in json format in php service before you sent.) Check this link;
http://www.sitepoint.com/lets-talk-1/
You can use services module for doing this. Also you need to install rest server
After this module is installed you can create your own endpoint in admin->structure->serviecs
You can add new custom rest services via views using services_views or in your custom module.
Create custom module then write the below code to manually create a REST service.
// services resources
function YOURMODULE_services_resources() {
$resources = array(
'ups' => array(
'actions' => array(
'yourservice' => array(
'help' => t('Service details.'),
'callback' => 'your_rest_api_callback_function',
'args' => array(),
'access arguments' => array('access content'),
'access arguments append' => false,
'args' => array(
array(
'name' => 'data',
'type' => 'array',
'description' => 'Arguments description.',
'source' => 'data',
'optional' => TRUE,
),
),
),
),
),
);
return $resources;
}
function your_rest_api_callback_function($data) {
// in $data you will get the passed arguments
$returnarr = "this is the content you need to return"
return $returnarr;
}
Then enable this services form your new api created in admin->structure->services
You can specify the return data format in this module configuration.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to upload update files for Android device updates. I need to upload two file extentions, first is .apk and the second is .upd. I have no problem with .apk but when I'm trying upload .upd files, it doesn't event get passed from validation.
I also tried it with simple PHP script, it only seems name and errors:
I couldn't find anyting on uploading .udp files with PHP or Laravel. I'd appreciatethe help, thank you very much.
Here is validation method:
private function validateRequest($request)
{
$fields = [
'file_type' => 'required',
'update_file' => 'required|file',
'swid' => 'required',
'software' => 'required',
'box_name' => 'required',
'apk_version' => 'sometimes|required',
'dongle_firmware_version' => 'sometimes|required',
'change_log' => 'required',
];
return Validator::make($request->all(), $fields )
->setAttributeNames([
'file_type' => 'File type',
'swid' => 'Software ID',
'software' => 'Software',
'box_name' => 'Box name',
'apk_version' => 'Android version',
'dongle_firmware_version' => 'Dongle firmware version',
'change_log' => 'Change log',
'update_file' => 'Update file'
]);
}
Error codes are documented. Yours is UPLOAD_ERR_INI_SIZE:
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
If you need to upload larger files, just allow a larger size ;-)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need to store the Laravel log into my database . Can you please help me?
Go to App/Exceptions/Handler.php and then write below code in report() function and define your model as an ErrorLog
$data = [
'id' => $this->createUniversalUniqueIdentifier(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'message' => $exception->getMessage(),
'trace' => $exception->getTraceAsString(),
];
$dataArr =['id' => $data['id'],
'file' => $data['file'],
'error_summary' => 'Line '.$data['line'].' '.$data['message'],
'log_trace' => $data['trace']
];
ErrorLog::create($dataArr);
Your Model file should be like that
ErrorLog.php
protected $table = 'logs';
protected $fillable =
['id',
'file',
'error_summary',
'log_trace'
];
Laravel supports Monolog for handling logs. Monolog supports many different handlers, including database handlers like the MongoDB handler.
You can use the MongoDB handler by adding a new channel to the channels array in your config/logging.php file, e.g.:
'channels' => [
'mongolog' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\MongoDBHandler::class,
'with' => [
'database' => 'mongo-database-name',
'collection' => 'log-collection-name',
],
],
Then you can set your default log channel to mongolog in your .env file, e.g. LOG_CHANNEL=mongolog.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Improve this question
So i have a class i have used couple of times for other non YII projects but now i want to use the same class in a YII2 project. I have done some searches but i kind of got stuck along the way. Below is what i have done so far:
I created a folder called "utility" in the vendor directory, the utility folder contains my class named "AT_Response.class.php". So my question is how do i include or call and use this class in my model or controller.
I have checked some links like :
https://www.yiiframework.com/doc/guide/2.0/en/tutorial-yii-integration
https://forum.yiiframework.com/t/not-understanding-how-to-use-external-php-library/79679
Class Code:
<?php
class AT_Response {
static private $response = array
(
'9999' => array('description' => "Unexpected Response", 'definite' => true, 'status' => "Indeterminate"),
'00' => array('description' => "Success", 'definite' => true, 'status' => "Success"),
'NNC_AUTH_01' => array('description' => /*"Status unknown, please wait for settlement report"*/"System Error", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_01' => array('description' => "Ttimed out", 'definite' => false, 'status' => "Indeterminate"),
'NNC_VTU_02' => array('description' => "Exceeded max number of requests for Phone number per time period", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_03' => array('description' => "Invalid target MSISDN supplied", 'definite' => true, 'status' => "Failure"),
'-1' => array('description' => "Not successful", 'definite' => false, 'status' => "Failure"),
);
static function getResponseByCode($respCode) {
if (isset(self::$response[$respCode]))
return self::$response[$respCode];
//else
return self::$response['9999'];
}
}
Thanks
With a few changes you can use any custom class as a helper component. You need to use namespace and use statement for the existing class you have, see the below
<?php
namespace app\components;
class Response
{
/**
* #var array
*/
private static $response = array
(
'9999' => array('description' => "Unexpected Response", 'definite' => true, 'status' => "Indeterminate"),
'00' => array('description' => "Success", 'definite' => true, 'status' => "Success"),
'NNC_AUTH_01' => array('description' => /*"Status unknown, please wait for settlement report"*/"System Error", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_01' => array('description' => "Ttimed out", 'definite' => false, 'status' => "Indeterminate"),
'NNC_VTU_02' => array('description' => "Exceeded max number of requests for Phone number per time period", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_03' => array('description' => "Invalid target MSISDN supplied", 'definite' => true, 'status' => "Failure"),
'-1' => array('description' => "Not successful", 'definite' => false, 'status' => "Failure")
);
/**
* #param $respCode
*/
public static function getResponseByCode($respCode)
{
if (isset(self::$response[$respCode])) {
return self::$response[$respCode];
}
return self::$response['9999'];
}
}
Save the Above class in a file called Response.php in app\components folder if using basic-app or common\components if you are using advanced-app but dont forget to change the namespace in the code.
You can then call the function getResponseByCode() like app\components\Response::getResponseByCode($responseCode) or common\components\Response::getResponseByCode($responseCode)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have an array what consist of arrays. Have a looks into this file gist.
How you can see each array repeats two times. I need to delete the second, I need to compare them by 'key' value of array.
Thanks!
The easiest way to get the result you expect is in my opinion this way:
$data = array(
array(
'domain' => 'messages',
'key' => 'test.testik',
'message' => array()
),
array(
'domain' => 'messages',
'key' => 'test2313.tes31231tik',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'valid.validik',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'joga.jimbo',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'valid.validik',
'message' => array()
)
);
$newdata = array();
foreach ($data as $subdata) {
$newdata[$subdata['key']] = $subdata;
}
$newdata = array_values($newdata); // reset array indizes
print_r($newdata);
The undefined offset 6 error is telling you that there isnt an array element at position 6. Without seeing your error message and your code I cant tell you where the error is But you would need to see if the element exists using something like this:
if (isset($array[index]))
{
//do something
}
This will handle the error, meaning you wont get the message, but you should see why the element doesnt exist, like Was there a problem when the arrays were made.
Your error message will tell you which line the problem was on and therefore which array variables are causing these errors.
UPDATE:
your code will always return true as you are comparing a value to itself therefore it will be an empty array.
$transll['key'] == $transll['key']
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a config files which store variable like this:
<?php
return array(
'debug' => true,
'url' => 'http://localhost',
'timezone' => 'UTC',
'locale' => 'en',
);
How can I retrieve it in object oriented way from main file? Thank you.
I'm not quite sure what sort of answer you're expecting when you say "in an object oriented way", but the way I'd do it would be something like the following:
$config = include("configfile.php");
And then you can just access the values like so:
echo $config["timezone"]; //prints "UTC"
i am guessing you wanted to convert this array to an object if so then use this.
<?php
return (object) array(
'debug' => true,
'url' => 'http://localhost',
'timezone' => 'UTC',
'locale' => 'en',
);
in the other page do this:
$config = include("configfile.php");
echo $config->locale;
This is not really a OOP concept, rather a PHP concept
Simply include the file:
$config = include 'config.php';