(01-17-2019, 08:35 PM)kilishan Wrote: You can use method spoofing in forms, though it appears that's not documented. Bad me. I just opened an issue at Github to make sure that gets done.
It would work like this:
Code:
<?php echo form_open('department/'.$department_item['id']); ?>
<input type="hidden" name="_method" value="delete" />
<button type="submit" class="button is-small btn-align accent-btn raised rounded btn-outlined">delete</button>
<?php echo form_close(); ?>
Sorry that won't work.
I have tried many many times yesterday and one thing works.
In the Routes:
PHP Code:
$routes->resource('department');
In the model:
PHP Code:
<?php
use CodeIgniter\Model;
class DepartmentModel extends Model
{
protected $table = 'department';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useSoftDeletes = true;
protected $allowedFields = ['name'];
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
}
In the form:
PHP Code:
<?php echo form_open('department/delete/'.$department_item['id']); ?>
<button type="submit" class="button is-small btn-align accent-btn raised rounded btn-outlined">delete</button>
<?php echo form_close(); ?>
Also works:
PHP Code:
<?php echo form_open('department/delete/'.$department_item['id']); ?>
<input type="hidden" name="_method" value="delete" />
<button type="submit" class="button is-small btn-align accent-btn raised rounded btn-outlined">delete</button>
<?php echo form_close(); ?>
In the controller:
PHP Code:
public function delete($id)
{
$model = new \DepartmentModel();
$model->delete($id);
return redirect()->to('/department');
}
So you can see that i added "delete/" in the form_open().
Without the "delete/" it wont work and takes the wrong method.
The documentation says:
PHP Code:
$routes->delete('photos/(:segment)', 'Photos::delete/$1');
And this happens also for the update method.
So i'm not a expert but what is wrong?
Have i coded the wrong way or is it a bug or is the manual not correct?
André