Home » Php » php – Yii2 backend bootstrap treeview url is not working properly

php – Yii2 backend bootstrap treeview url is not working properly

Posted by: admin February 25, 2020 Leave a comment

Questions:

I integrated AdminLTE with Yii2 framework, created the model and generated the CRUD models without any issues. But when I try the treeview URL to access the page, it’s showing a page not found error and I don’t know how to fix this issue.

Could you please tell me what’s wrong with my code ?

<ul class="sidebar-menu" data-widget="tree">
    <li class="header">MAIN NAVIGATION</li>
    <li>
        <a href="index.php">
            <i class="fa fa-dashboard"/>
            <span>Dashboard</span>
        </a>
    </li>

    <li class="treeview">
        <a href="#">
           <i class="fa fa-user"></i>
           <span>User</span>
        </a>
        <ul class="treeview-menu">
            <li>
                <a href="index.php?r=users/create">
                    <i class="fa fa-user-circle"/>Create User
                </a>
            </li>
            <li>
                <a href="index.php?r=users">
                    <i class="fa fa fa-eye"/>View User
                </a>
            </li>
        </ul>
    </li>
</ul>

And I attached the Image error message screenshots.

How to&Answers:

Could it be a singular/plural problem in your link? Is your controller class named UserController or UsersController?

If you’re following the Yii schema design guidelines, your users model / controller should be named User. So your link should be <a href="index.php?r=user/create"> and
<a href="index.php?r=user">

You should also consider to write your links using Yii’s helpers Url::to that take care of every aspect of your application’s configuration:

<?= Url::to(['user/index']) ?>