简体   繁体   中英

Yii 2.0 static link to a controller

I'm very new to Yii 2.03 (and frameworks in general). I'm facing some problem now.

On the main page I have a menu on which I want to place (in the view) the link to the controller, but I don't know how, I'm getting " PHP Fatal Error – yii\\base\\ErrorException Class 'CHtml' not found" or " PHP Fatal Error – yii\\base\\ErrorException Class 'Html' not found"

http://localhost/web/index.php is the main page with the menu. http://localhost/web/index.php?r=autori/index is the page with the generated CRUD, which works perfectly. In the view I have <li><a href="#">Autori</a></li> and I want to replace the '#' with a valid link, I don't care for SEO now. How can I edit the view to use the specific controller?

Thanks!

If you are indeed using Yii2, then try using:

<li><a href="<?=Url::to(["autori/index"])?>">Autori</a></li>

You'll need to include this in the beginning of your view file, so it uses the correct namespace for the Url helper class:

<?php use yii\helpers\Url ?>

But pay attention to the framework version, as Sliq noted, CHtml is a Yii1 class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM