O
O
OlegBas19962018-08-23 12:07:19
Yii
OlegBas1996, 2018-08-23 12:07:19

CRUD YII2 problem when deleting a record from a table?

Hello! I create an admin panel, generated CRUD via gii for the users table, registered routes in the web.php file. When an entry is deleted from the users table, it redirects to a non-existent page. Interestingly, for the pages for adding and updating a record, I did not prescribe routes, and they work. Help solve the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-08-24
@OlegBas1996

You make return $this->redirect(['index']);
url manager rules

'/' => 'site/index', 
                'article/short/<id:\d+>' => 'site/article/',
                'article/full/<id:\d+>' => 'site/fullarticle/',
                'addClick/<idClickBlock:\d+>' => 'site/addclick',
                'admin' => 'admin/default/',
                'admin/news' => 'admin/news/',
                'admin/tizers' => 'admin/tizer/',
                'admin/sections' => 'admin/section/',
                'admin/users' => 'admin/user/',

What rule do you think should work for the route to work? ['index']
With your config, as I understand it, the redirect should look like this:
public function actionDelete($id)
    {
        $this->findModel($id)->delete();
        return $this->redirect(['admin/news/]);
    }

But maybe you have 404 even before that, even at the stage of searching for a delete action

E
Evgeny Bukharev, 2018-08-23
@evgenybuckharev

'enableStrictParsing' => true, // чтобы "я не прописывал маршруты,и они работают."

As an option, add basic routes to the very end of the rules, and prescribe more custom routes above
// Base
'<action>' => 'site/<action>',
'<controller>/<action>' => '<controller>/<action>',
'<module>/<controller>/<action>/<id:\w+>' => '<module>/<controller>/<action>',
'<module>/<controller>' => '<module>/<controller>/index',
'<module>/<controller>/<action>' => '<module>/<controller>/<action>',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question