在我的控制器中调用数据库视图和模型 [英] Database views and models being called in my controller

查看:78
本文介绍了在我的控制器中调用数据库视图和模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Cakephp 3有点陌生,我试图弄清楚您如何在索引控制器中调用此简单模型/表,以便我可以将这些值显示在我的网页上。

I am a little new to cakephp 3 and i am trying to figure out how you call this simple model/table in my index controller so that i can get the values to show up on my webpage.

这是我在sql管理中的视图vCalcTranscriptUpdateTerms

this is my view vCalcTranscriptUpdateTerms in sql management

然后这是我的模型/表代码

then this is my code for the model/table

由于它只是一个非常非常基本的表,所以我只放置了一个statemnt来加载视图。

due to it being a very very basic table of just 1 i only put 1 statemnt just to load the view.

<?php

namespace App\Model\Table;

use Cake\ORM\Table;

class UpdatedTranscriptsTable extends Table
{
public function initialize(array $config)
    {
        $this->setTable('preload.vCalcTranscriptUpdateTerms');
    }
}

现在我已经为该视图设置了表格我到底该在控制器中调用该表并从中获取所有信息吗?

now that i have a table set to that view how the heck do i call that table in my controller and get all of the information out of it?

推荐答案

在控制器顶部包括以下用于访问模型的代码

at the top of controller include the below code for accessing the models

使用Cake\ORM\TableRegistry;

use Cake\ORM\TableRegistry;

,然后添加in before过滤器函数或initiate函数
中,或者您可以在确实存在的任何函数中使用它

and you add the in before filter function or in initialize function or you can use it inside any function where you have indeed

$ this-> loadModel('UpdatedTranscripts') ;

$this->loadModel('UpdatedTranscripts');

这篇关于在我的控制器中调用数据库视图和模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆