Where is unset_list and unset_back_to_list?

I’m porting a grocerycrud 1.x app to version 2.x and I can’t find an equivalent for unset_list and unset_back_to_list. How is this done in version 2?

Basically what I’m trying to accomplish is to display the edit page for a specific record without the option of returning to the list of all records, or ever displaying that list.

Thanks.

Hello @ctnadovich and welcome to the forums. Unfortunately the unset_back_to_list was removed from version 2 and 3. The main problem was that it was difficult to isolate the form to run as standalone. I want to revisit this though this in the future (but not the near future sorry).

That’s so unfortunate. A typical use case is with a database of users. Each user should be able to edit their own profile record, but no-one else’s. I can’t believe your v2.x doesn’t support this very simple and common use case, as it did just fine in v1.x

I understand that your removed the functions, but how do people work around this omission? Surely there are many people using GroceryCrud to manage a table of users. What did they do when you removed these functions? How did they allow each individual user to edit their own record in that user table? It would be a shame to have to hand code a separate form outside GroceryCrud to accomplish this. Is that what people were forced to do?

To answer my own question, I guess there are two workaround I’ve thought of. One is to simply use a where clause to restrict the list to just one record. Sort-of a preview read-only view. The user then needs to click edit to change anything. Not quite as good as going directly to the edit page, but it’s OK in some cases.

Another workaround is to filter the $output of render() to remove the buttons, maybe like this

 $output->output = str_replace("value='Update changes'", "value='Save'", $output->output);
 $output->output = str_replace("value='Update and go back to list'", "value='Save and Return'", $output->output);

and then use logic in the controller and CodeIgniter 4 routes to jail into edit form.

I’ve used both these techniques to port my v1.x forms that use unset_list()

Typical controller logic to jail into edit

        $state = $crud->getState();
        $state_info = $crud->getStateInfo();
        switch ($state) {
            case 'edit':
            case 'update_validation':
            case 'update':
            case 'success':
                $primary_key = $state_info->primary_key;
                $member_id = $this->session->get('user_id');
                if ($primary_key != $member_id) {
                    trigger_error("ID Mismatch: pk=$primary_key; mi=$member_id", E_USER_ERROR);
                }
                break;
            default:
                trigger_error("This function can only be called in states edit/update_validation/success. State=$state", E_USER_ERROR);
                break;
        }