简体   繁体   中英

how to connect the data from backend to frontend using links in Yii framework

I need to access the data from a backend file by using a link in frontend.

Find the code below :

     $model = new LoginForm();
    if ($model->load(Yii::$app->request->post()) && $model->login()) {
        return $this->render('hello');
    } else {
        $model->password = '';

        return $this->render('login', [
            'model' => $model,
        ]);
    } 

In the above code instead of hello, I need to pass to farmers page which is in the following location "C:\\xampp\\htdocs\\f_project_yii\\backend\\views\\farmer".

One of solution to set absolute path to view like this

$model = new LoginForm();
    if ($model->load(Yii::$app->request->post()) && $model->login()) {
        return $this->render('/farmer');
    } else {
        $model->password = '';

        return $this->render('login', [
            'model' => $model,
        ]);
    } 

When you are use a

$this->render('hello');

You must to have a ./protected/views/[Controller name in lowcase]/hello.php file

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