Thursday, April 12, 2018

Yii Actions

Create action in Yii2

Yii actions define public under the controller class. It starts with action keyword and it can be camel case like actionTestScript.

Yii Url format like: controller/action.

In below example controller name is sample and action name is TestScript, So if you want to access this controller/action, You need to write like sample/test-script.

Another example is sample/home.

use yii\web\Controller;
namespace app\controllers;

class SampleController extends Controller
{
    public function actionTestScript($params)
    {
        return $this->render('test');
    }

    public function actionHome()
    {
        return 'This is my controller';
    }
}

2 comments:

  1. Nice Blog , This is what I exactly Looking for , Keep sharing more blog .
    Hire Yii Developers in India

    ReplyDelete
  2. Useful content! Businesses can Hire Yii developers from HireFullStackDeveloperIndia to rapidly build scalable PHP Programs.

    ReplyDelete

Recent Update

yii2 session handling

use yii\web\Session; $session = Yii::$app->session; // start session $session->open(); // close session $session->close(); ...

Most Search