You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CI4: Views/attributes/item.php not loading values in dropdown nor current attributes in New/Edit Item form view #3855
getAttributes() then calls the views/attributes/item.php view to display the dropdown and the existing attributes, but since those are all empty, a blank dropdown and no attributes are displayed.
Expected behavior:
definition_ids in the get request would not be null
on new items a complete dropdown of the available attributes would be output in the view
on existing items a dropdown with undefined attributes would be displayed along with existing attributes.
Next Steps:
We need to research why definition_ids in the request is null. It's possible that the problem is in the form view or sooner, so they are never getting populated.
I wonder how it worked before, were the definition ids coming from the frontend? Perhaps this was just the contents of the dropdown list sent back (as you need to add an attribute to an item in a first step).
Also I wonder if all of this just came in through query string parameter, encoded in json? I would need to check the master version to understand.
@jekkos I think we are talking about this line $builder->where('definition_flags &', $definition_flags);.
I think that means we want it to produce WHERE 'ospos_definition_flags' &= [definition_flags] where [definition_flags] is the value passed into the function. In PHP the function is defining this as an int, but in the database it's a tinyint(1), so I think this is part of why that was in there. I'll try to debug this tomorrow to see what SQL is actually being produced.
$builder->where('definition_flags &', $definition_flags); produces WHERE definition_flags& = 1
Adding the escape parameter $builder->where('definition_flags &', $definition_flags, false); gets rid of the escaping issue, but it still fails. WHERE definition_flags & = 1
After doing a bit of research, this is because &= is valid SQL, but not valid MySQL. Changing the code to $builder->where(new RawSql("definition_flags & $definition_flags"));
will produce WHERE definition_flags & 1
so that is what we may need to do, but doing so unfortunately doesn't resolve this issue.
Something to be noted about RawSql(), which is new as of CI4.2.0, is that their documentation gives strong warning to escape values and protect identifiers manually. How should we go about doing this? I'm more gun-shy about using esc() since we needed to rip out a bunch of them for having messed up the data.
var refresh = function() {
var definition_id = $("#definition_name option:selected").val();
var attribute_values = definition_values();
attribute_values[definition_id] = '';
$('#attributes').load('<?= "items/attributes/$item_id" ?>', {
'definition_ids': JSON.stringify(attribute_values)
}, enable_delete);
};
The first does not send definition_ids and breaks it so that no attribute values are sent to the views/attributes/item.php view. Is there any reason why I can't change your code to a hybrid of the two?
After further testing, I think the reason you added the if statement is because passing null in the first parameter of json_decode() is deprecated. I think this can be resolved by using the null coalescing operator ??, so $definition_ids = json_decode($this->request->getGet('definition_ids') ?? '', TRUE);
@objecttothis . I don't know what is going on with the following error. This is happening when I add or update an Items form. This has been here for a while. Current Ci4-upgrade. Only modification recently was changing the way the form finally displays attributes. Any ideas would be helpful.
CRITICAL - 2023-11-07 12:34:28 --> Unable to connect to the database.
Main connection [MySQLi]: Trying to access array offset on value of type bool
in SYSTEMPATH\Database\BaseConnection.php on line 427.
1 SYSTEMPATH\Session\Handlers\DatabaseHandler.php(109): CodeIgniter\Database\BaseConnection->initialize()
2 [internal function]: CodeIgniter\Session\Handlers\DatabaseHandler->open('sessions', 'ospos_session')
3 SYSTEMPATH\Session\Session.php(928): session_start()
4 SYSTEMPATH\Session\Session.php(250): CodeIgniter\Session\Session->startSession()
5 SYSTEMPATH\Config\Services.php(674): CodeIgniter\Session\Session->start()
6 SYSTEMPATH\Config\BaseService.php(252): CodeIgniter\Config\Services::session(Object(Config\App), false)
7 SYSTEMPATH\Config\BaseService.php(193): CodeIgniter\Config\BaseService::__callStatic('session', [...])
8 SYSTEMPATH\Config\Services.php(641): CodeIgniter\Config\BaseService::getSharedInstance('session', null)
9 SYSTEMPATH\Config\BaseService.php(252): CodeIgniter\Config\Services::session()
10 SYSTEMPATH\Common.php(979): CodeIgniter\Config\BaseService::__callStatic('session', [])
11 APPPATH\Models\Employee.php(32): session()
12 SYSTEMPATH\Config\Factories.php(129): App\Models\Employee->__construct(null)
13 SYSTEMPATH\Config\Factories.php(86): CodeIgniter\Config\Factories::__callStatic('models', [...])
14 SYSTEMPATH\Common.php(818): CodeIgniter\Config\Factories::models('Employee', [...], null)
15 APPPATH\Controllers\Secure_Controller.php(26): model('Employee')
16 APPPATH\Controllers\Items.php(45): App\Controllers\Secure_Controller->__construct('items')
17 SYSTEMPATH\CodeIgniter.php(906): App\Controllers\Items->__construct()
18 SYSTEMPATH\CodeIgniter.php(490): CodeIgniter\CodeIgniter->createController()
19 SYSTEMPATH\CodeIgniter.php(368): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
20 FCPATH\index.php(67): CodeIgniter\CodeIgniter->run()
I've been troubleshooting that error most of the day today. I posted on the code igniter forum. There are problems with the attributes save functions. I suspect that the stack trace is masking another problem.
App/views/items/form starting at line 576 on my version. Checkitemnumber gave me no issues. I tried adding back individual checks but after 3 to 4 edits it would create the same issue. I also noticed an improvement in the speed of the form updating.
Hmmm. I commented out the rules section, but had the same errors in the log Error connecting to the database: ErrorException: Trying to access array offset on value of type bool. I get those errors when I edit an item and change the value of an attribute. Let's make sure that we are both running the same code though. I can't remember, do you know how to pull down the latest version of a branch using github desktop or another tool? If you need, I can show you how to build a project to make it easier.
Yes I noticed that this issue was still there but it was not preventing the model from doing the update. I use github to download the current versions and work from that. And I merge from the ci4-upgrade branch.
Activity
jekkos commentedon Nov 4, 2023
I wonder how it worked before, were the definition ids coming from the frontend? Perhaps this was just the contents of the dropdown list sent back (as you need to add an attribute to an item in a first step).
Also I wonder if all of this just came in through query string parameter, encoded in json? I would need to check the master version to understand.
odiea commentedon Nov 4, 2023
The following function in Models/Attribute also creates errors. It does not like the & symbol.
jekkos commentedon Nov 5, 2023
Thanks for pointing that out @odiea . The `&= was used as a bit field operator. Maybe the query builder does not support this notation anymore.
objecttothis commentedon Nov 5, 2023
@jekkos I think we are talking about this line
$builder->where('definition_flags &', $definition_flags);.I think that means we want it to produce
WHERE 'ospos_definition_flags' &= [definition_flags]where [definition_flags] is the value passed into the function. In PHP the function is defining this as an int, but in the database it's a tinyint(1), so I think this is part of why that was in there. I'll try to debug this tomorrow to see what SQL is actually being produced.objecttothis commentedon Nov 5, 2023
According to the documentation (https://codeigniter.com/user_guide/database/query_builder.html#custom-key-value-method) we may need to include the whole operator
&=rather than just part of it.objecttothis commentedon Nov 5, 2023
$builder->where('definition_flags &', $definition_flags);producesWHEREdefinition_flags&= 1Adding the
escapeparameter$builder->where('definition_flags &', $definition_flags, false);gets rid of the escaping issue, but it still fails.WHERE definition_flags & = 1After doing a bit of research, this is because
&=is valid SQL, but not valid MySQL. Changing the code to$builder->where(new RawSql("definition_flags & $definition_flags"));will produce
WHERE definition_flags & 1so that is what we may need to do, but doing so unfortunately doesn't resolve this issue.
objecttothis commentedon Nov 5, 2023
Something to be noted about
RawSql(), which is new as of CI4.2.0, is that their documentation gives strong warning to escape values and protect identifiers manually. How should we go about doing this? I'm more gun-shy about usingesc()since we needed to rip out a bunch of them for having messed up the data.objecttothis commentedon Nov 6, 2023
@SteveIreland in the Items controller you reworked the beginning of the
getAttributes()function from thisto this
getAttributes()is called from views\items\form.phpand from views\attributes\items.php
The first does not send definition_ids and breaks it so that no attribute values are sent to the views/attributes/item.php view. Is there any reason why I can't change your code to a hybrid of the two?
objecttothis commentedon Nov 6, 2023
After further testing, I think the reason you added the if statement is because passing null in the first parameter of json_decode() is deprecated. I think this can be resolved by using the null coalescing operator
??, so$definition_ids = json_decode($this->request->getGet('definition_ids') ?? '', TRUE);objecttothis commentedon Nov 6, 2023
That resolved the problem and I fixed a few other issues. Now onto the next one. updating the attribute_links is failing.
jekkos commentedon Nov 6, 2023
great work @objecttothis
odiea commentedon Nov 7, 2023
@objecttothis . I don't know what is going on with the following error. This is happening when I add or update an Items form. This has been here for a while. Current Ci4-upgrade. Only modification recently was changing the way the form finally displays attributes. Any ideas would be helpful.
objecttothis commentedon Nov 7, 2023
I've been troubleshooting that error most of the day today. I posted on the code igniter forum. There are problems with the attributes save functions. I suspect that the stack trace is masking another problem.
objecttothis commentedon Nov 8, 2023
Here is the forum post. I am working on another project today so if anyone has any ideas, feel free to offer them. https://forum.codeigniter.com/showthread.php?tid=88789
odiea commentedon Nov 8, 2023
I found the issue. In items form I commented out rules and have not had this problem. It appears that checkNumeric is creating this problem.
objecttothis commentedon Nov 9, 2023
OK, I'll play around with checkNumeric. Can you post specifically what you commented out?
odiea commentedon Nov 9, 2023
App/views/items/form starting at line 576 on my version. Checkitemnumber gave me no issues. I tried adding back individual checks but after 3 to 4 edits it would create the same issue. I also noticed an improvement in the speed of the form updating.
objecttothis commentedon Nov 9, 2023
Hmmm. I commented out the rules section, but had the same errors in the log
Error connecting to the database: ErrorException: Trying to access array offset on value of type bool. I get those errors when I edit an item and change the value of an attribute. Let's make sure that we are both running the same code though. I can't remember, do you know how to pull down the latest version of a branch using github desktop or another tool? If you need, I can show you how to build a project to make it easier.odiea commentedon Nov 9, 2023
Yes I noticed that this issue was still there but it was not preventing the model from doing the update. I use github to download the current versions and work from that. And I merge from the ci4-upgrade branch.
odiea commentedon Nov 9, 2023
I name the website from who has been doing the current updates.
