Custom error message for the "file required" in zf2 - file-upload

This is config for the input factory:
'name' => 'file',
'type' => 'Zend\InputFilter\FileInput',
'required' => true,
When I submit the form without "file" there's no error showing up saying something like "the field file is required". However, if I add the "error_message" the error is showing up, but it overrides other error messages from other validators in this input. When working with regular inputs I add the following validator:
[
'name' => 'not_empty',
'options' => [
'message' => 'Field is required'
]
]
But, I can't do this with FileInput.
Is there any way to set the custom message for the required field in case if "FileInput" is used?

Related

Setting unknown property: yii\log\Logger::targets

After Installed the Yii in my system when I try to run it getting this error.
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\log\Logger::targets
Here is some of the documentation I created while implementing logging in Yii, it might be of your help:
========================= Configure xampp to send the emails from localhost code ==========================================
Changes for C:\xampp\php\php.ini file:
search for [mail function]:
[mail function]
SMTP=localhost to SMTP=smtp.gmail.com
smtp_port=587
sendmail_from=me#example.com to sendmail_from=your email address
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off
mail.log = syslog
Changes for C:\xampp\sendmail\sendmail.ini:
search for [sendmail]:
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=same as "sendmail_from" in php.ini file
auth_password=generated password for the email account
force_sender= same as "auth_username" in this file
================================================ Restart Xampp Server =====================================================
=================================================== Add table in DB =======================================================
drop table if exists "log";
create table "log"
(
"id" number(20) NOT NULL PRIMARY KEY,
"level" integer,
"category" varchar(255),
"log_time" number,
"prefix" text,
"message" text,
key "idx_log_level" ("level"),
key "idx_log_category" ("category")
);
============================================ Configuration in Yii2 project ================================================
add in "components" array in app\config\console.php and app\config\web.php both files:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'your email address (for testing on localhost use same as in ini files)',
'password' => 'generated password',
'port' => 587,
'encryption' => 'tls',
],
], //end of mailer
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning','info'],
],
[
'class' => 'yii\log\DbTarget',
'levels' => ['error', 'warning','info'],
],
[
'class' => 'yii\log\EmailTarget',
'mailer' => 'mailer',
'levels' => ['error', 'warning','info'],
//'categories' => ['yii\db\*'],
'message' => [
'from' => ['your email address(for testing on localhost use same as in ini files)'],
'to' => ['receiptent email address'],
],
],
], // end of targets
'flushInterval' => 1,
], //end of logs
//------------------------ web.php (log configuration setup) -------------------------//
//categories name would be later assgined to messages:
Yii::info($message, 'userNotification');

Unexpected 404 Not Found Error in Laravel (5.8)

I have these lines in api.php
Route::apiResources([
'users' => 'Api\UserController',
'products' => 'Api\ProductController',
'categories' => 'Api\CategoryController',
]);
Route::get('/users/custom1', 'Api\UserController#custom1');
When I have them in this order and I call the route I get 404 Not Found.
But when I change the order, I get result:
Route::get('/users/custom1', 'Api\UserController#custom1');
Route::apiResources([
'users' => 'Api\UserController',
'products' => 'Api\ProductController',
'categories' => 'Api\CategoryController',
]);
This situation has frustrated me because I thought the error originated from the model and find method:
public function custom1()
{
$user2 = User::find(2);
return $user2;
}
Because I was checking the result in Postman and it shows the error like this when you ask for application/json as response:
{
"message": "No query results for model [App\\User] custom1",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"file": "C:\\wamp64\\www\\laravel-api\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Exceptions\\Handler.php",
"line": 204,
"trace": [
{...
What is the reason of this change?
Because in both situations I can see the route in route:list.
Ok, I have realized the reason when I checked route:list with a clearer mind.
Laravel shows route:list in alphabetical order but actually the order we write in route file matters right?
So, it occured to me that if this line is coming first:
Laravel is trying to use custom1 as a route parameter.
So I must define this specific route before api resource routes:
Route::get('/users/custom1', 'Api\UserController#custom1');
Route::apiResources([
'users' => 'Api\UserController',
'products' => 'Api\ProductController',
'categories' => 'Api\CategoryController',
]);

DarkaOnLine / L5-Swagger with Laravel Sanctum Swagger UI

I found The solution. to add token to header
add follwing code in /config/l5-swagger in security array
'sanctum' => [ // Unique name of security
'type' => 'apiKey', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
'description' => 'Bearer',
'name' => 'Authorization', // The name of the header or query parameter to be used.
'in' => 'header', // The location of the API key. Valid values are "query" or "header".
],
then in your SWG Annotation put
security={
* {"sanctum": {}},
* },

Mollie applicationfee's

for a customer I need to charge an applicationFee for each order that has been processed on their site from the sub customers. The whole code is working with authentication and everything.
But from the moment I'm adding:
'applicationFee' => $applicationFee
to the call I receive this error:
Error executing API call (422: Unprocessable Entity): Unable to process application request for this account. Documentation: https://docs.mollie.com/guides/handling-errors"
The content of "$applicationFee" is correct, that I was able to check already.
The $shop_mollie_data->profile_id containts the different websiteprofileId's found on the Mollie dashboard.
$provider = new MollieConnectProvider($request, $clientId, $clientSecret, $redirectUrl);
$newAccessToken = $provider->getRefreshTokenResponse($shop_mollie_data->refresh_token);
$mollie = new MollieApiClient();
$mollie->setAccessToken($newAccessToken['access_token']);
$payment = $mollie->payments->create([
'amount' => [
'currency' => 'EUR',
'value' => (string) (sprintf("%.2f", $order_total))
],
'description' => ucfirst($shop->name) . ' - Order #' . $order_nm,
'webhookUrl' => $url_callback,
'redirectUrl' => $url_success,
'method' => 'bancontact',
'locale' => $language_id,
'metadata' => [
"order_id" => $ref,
"shop id" => $shop->id
],
'profileId' => $shop_mollie_data->profile_id,
'testmode' => true,
'applicationFee' => $applicationFee
]);

assertTitle fails on Selenium + PHPUnit

I am trying a very simple test like this :
public function index()
{
$this->open('');
$this->assertTitle(Yii::app()->name);
}
with the appropriate fixtures :
'accueil' => array(
'id' => 1,
'title' => Yii::app()->name,
'name' => "accueil",
[etc...]
),
But when I run the functional test, the assertTitle method fails :
Failed command: assertTitle('comptabilite-personnelle.net (dev)')
Failed asserting that 'comptabilite-personnelle.net (dev)' matches
PCRE pattern "/^comptabilite-personnelle.net (dev)$/".
OTOH, the following code does not fail :
Fixtures :
'accueil' => array(
'id' => 1,
'title' => 'whatever',
'name' => "accueil",
[etc...]
),
Assertion :
$this->assertTitle('whatever');
Any idea about this behavior welcome !
If you just want to check if your page title contains you app name and not want to check if your page title is exactly the same as your app name you need to do it like that:
$this->assertTitle('regexp:.*' . Yii::app()->name . '.*');