URL Management

Hi guys,

I have a question about Url management:

In web.php configuration ( I am using basic template )




'urlManager' => [

            'class'           => 'yii\web\UrlManager',

            // Disable index.php

            'showScriptName'  => false,

            // Disable r      = routes

            'enablePrettyUrl' => true,

            'rules' => array(

                'activities/more/<page:\d+>'             => 'activities/more',

                '<controller:\w+>/<id:\d+>'              => '<controller>/view',

                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

                '<controller:\w+>/<action:\w+>'          => '<controller>/<action>',

            ),

        ],



I added


'activities/more/<page:\d+>'  => 'activities/more',

and controller




public function actionMore($page = 1)

    {

    	$activities = Activity::find()

			->orderBy('id DESC')

			->limit(5)

			->offset(($page - 1) * 5)

			->all();


		if (!empty($activities)) {

			return $this->renderPartial('@widget/views/activities/_list', [

    				'errors' => '', 

    				'activities' => $activities

    			]);

		}

		else {

			echo "<p class='no-more'>No activity is available</p>";

			exit();

		}

    }



and it’s working for me.

But when in web.php configuration :

I want to set


 'activities/viewmore/<page:\d+>' => 'activities/viewmore',

instead of


 'activities/more/<page:\d+>' => 'activities/more',

and in controller




public function actionViewMore($page=1) {

.....

....


}



but it’s not working anymore. I don’t know what’s issue? Please help me.

Thanks in advance

Try rename your action from actionViewMore to actionViewmore

yes, it’s working now, thank you very much. Could you please tell me why?

So if I have a action with more than 3 words, I only named uppercase first character of first word, right?

Example:

URL viewmore runs actionViewmore() BUT

URL view-more runs actionViewMore()

Character “-” is translated into uppercase character. It’s because you cant named function actionView-more() { … }