Home  >  Article  >  Backend Development  >  In Yii2.0, I want to jump from the admin module in the background to the module in the front desk. How to jump?

In Yii2.0, I want to jump from the admin module in the background to the module in the front desk. How to jump?

WBOY
WBOYOriginal
2016-10-10 11:56:121246browse

The yiihelperUrl::to(); jump
code is as follows. It is now in the background admin module

<code> <a href="<?php echo yii\helpers\Url::to(['product/detail','productid'=>$product->productid]); ?>" class="name"><?php echo $product->title; ?></a>
</code>

I want to jump to the detail method of the Product controller in the foreground.
I get an error when I jump. Because there is no such controller and method in the backend module, it cannot be found

Reply content:

The yiihelperUrl::to(); jump
code is as follows. It is now in the background admin module

<code> <a href="<?php echo yii\helpers\Url::to(['product/detail','productid'=>$product->productid]); ?>" class="name"><?php echo $product->title; ?></a>
</code>

I want to jump to the detail method of the Product controller in the foreground.
I get an error when I jump. Because there is no such controller and method in the backend module, it cannot be found

<code> <a href="<?php echo Yii::$app->urlManager->createAbsoluteUrl(['product/detail','productid'=>$product->productid]); ?>" class="name"><?php echo $product->title; ?></a>
</code>

Url::to generates a path relative to the current module, while the above method generates an absolute path.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn