A
A
AlexSer2019-05-21 14:36:42
Yii
AlexSer, 2019-05-21 14:36:42

How to remove duplicate URL in Yii2?

Hello everybody! I decided to display part of the application in a separate module.
Block module.

class BlockController extends Controller
{
    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionIndex()
    {
                 return $ this ->render('index');
     }  

     public function actionCreate(){
     }

When I visit the /localhost/block link, the index-Action fires.
But when I submit the form to actionCreate(), by url /block/create, I get an error. Works only on /block/block/create
Question: How to remove repeated block from url?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav, 2019-05-21
@nskarl

/block/block/create - logical url, because this is a module,
write the route handles in the rules
'block/create' => 'block/block/create',
but this is not quite the right approach.
if the url like /block/create is important to you,
then it is better to create another controller CreateController in which to make the actionIndex() { ... } method,
then the page will become available at /block/create
, this is a better solution than to fence the garden in the rules

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question