KrisPBacon
(KrisPBacon)
January 26, 2023, 12:35pm
1
I upgraded to php 8.2 and when using FullCalendar, I get a 400 Bad request message and the debug shows a Missing Parameter: _
yii\web\BadRequestHttpException: Missing required parameters: _ in C:\xampp\htdocs\atmtest\vendor\yiisoft\yii2\web\Controller.php:194
Here is the link to the question on Stack overflow with more details.
https://stackoverflow.com/questions/75225080/request-failed-xhr-xmlhttprequest-400-bad-request
tri
(tri - Tommy Riboe)
January 26, 2023, 3:08pm
2
You call this Yii2 action:
public function
actionJsoncalendar($start=NULL,$end=NULL,$_=NULL,$wphid)
{
from JS, passing only one parameter (wphid)
Did this work before? Which PHP version?
I guess the relevant Yii2 core code is:
public function bindActionParams($action, $params)
{
...
...
foreach ($method->getParameters() as $param) {
$name = $param->getName();
if (array_key_exists($name, $params)) {
...
} elseif (
...
} elseif ($param->isDefaultValueAvailable()) {
$args[] = $actionParams[$name] = $param->getDefaultValue();
} else {
$missing[] = $name;
}
}
if (!empty($missing)) {
throw new BadRequestHttpException(
Yii::t('yii', 'Missing required parameters: {params}', ['params' => implode(', ', $missing)])
);
}
KrisPBacon
(KrisPBacon)
January 26, 2023, 3:55pm
3
This worked on PHP 7.4 before. There was no other changes to the code.
tri
(tri - Tommy Riboe)
January 27, 2023, 9:56am
4
I would try if this works:
public function
actionJsoncalendar($wphid, $start=NULL,$end=NULL,$_=NULL)
{
Worth a try.
I don’t know how Reflection will handle the parameters.
From php.net (perhaps less relevant):
As of PHP 8.0.0, declaring mandatory arguments after optional arguments is deprecated .
and
As of PHP 8.0.0, named arguments can be used to skip over multiple optional parameters.
KrisPBacon
(KrisPBacon)
January 27, 2023, 11:58am
5
Thank you, this stopped the 400 error.
I did not realize the $_ is a optional argument.
I didn’t write this code, just trying to debug it.
I am just trying to fix “Trying to access array offset on value of type bool” now.
$approvedtill = Yii::$app->db->createCommand(‘select wph_enddate FROM wpheader where wph_id = (SELECT max(wph_id) FROM wpheader where wph_empid = :empid and wph_status > 0)’, $params)
->queryOne();
$times = Planner::find()->joinWith([‘task’,‘header’])->where([‘pl_empid’ => $empid])->all();
foreach ($times AS $time){
$data[] = array(
‘id’ => $time->pl_id,
‘title’ => $time->pl_title,
‘start’ => date(‘Y-m-d H:i:s’,strtotime($time->pl_start)),
‘end’ => date(‘Y-m-d H:i:s’,strtotime($time->pl_end)),
‘color’ => ($time->pl_title == ‘Lunch’) ? ‘#378006 ’ : ($time->task->task_priority == ‘Urgent’ ? ‘#a60a0d ’ : ($time->task->task_priority == ‘High’ ? ‘#ad3a05 ’ : ($time->task->task_priority == ‘Medium’ ? ‘#610861 ’ : ($time->task->task_priority == ‘Low’ ? ‘#086118 ’ : ‘#05a321 ’)))),
‘editable’ => ($time->pl_start > $approvedtill[‘wph_enddate’]) ? true : false,
);
}
tri
(tri - Tommy Riboe)
January 27, 2023, 12:14pm
6
KrisPBacon
(KrisPBacon)
January 27, 2023, 1:05pm
7
Thank for the help.
Any further debugging will be done in the future.
I used this piece of code
if(!$approvedtill){
$approvedtill = date(“Y-m-d”);}