Home  >  Article  >  Backend Development  >  thinkphp view model query prompt ERR: 1146: Table 'db.pr_order_view' doesn't exist solution, vieworder_PHP tutorial

thinkphp view model query prompt ERR: 1146: Table 'db.pr_order_view' doesn't exist solution, vieworder_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:15:371349browse

thinkphp view model query prompt ERR: 1146: Table 'db.pr_order_view' doesn't exist solution, vieworder

This article describes the example of thinkphp view model query failure prompt: ERR: 1146: Table 'db.pr_order_view' doesn't exist solution. Share it with everyone for your reference. The specific method is as follows:

1. Problem description:

I want to use thinkphp's view model to perform related queries, but the result is this problem (log record): ERR: 1146: Table 'db.pr_order_view' doesn't exist, I wonder how the view model comes out of sql That’s it, the view model is as follows:

Copy code The code is as follows:
class OrderViewModel extends ViewModel
{
public $viewFields = array(
'Order' =>array(
'_as'=>'Orders', //Rename to avoid conflict with system syntax
'id'=>'oid',
'ordid',
'user',
'product',
'status',
'paynum',
'cat',
'payment_trade_no',
'ip'=>'mip',
'reserve_time',
'createtime',
'payment_trade_status',
),
'Member'=>array(
'id'=>'mid',
'name'=>'uname',
'cardnum',
'tel',
'reg_time',
'reg_ip',
'qq',
'email',
'address',
'last_login_time',
'last_login_ip',
'_on'=>'Orders.user=Member.id'
),
'Product'=>array(
'id',
'shorttitle',
'img1',
'category',
'_on'=>'Orders.product=Product.id'
),
);
}
?>

2. Solution:

I read a lot of manuals and Baidu, but I didn’t find a solution, and there was nothing wrong with calling $Form = D('Admin/OrderView'); (I used grouping here). After checking it myself, it turned out that there was a problem. It turns out that the name of the view model is wrong, OrderView.class.php, it should be OrderViewModel.class.php normally.

ThinkPHP beginners should especially be careful not to make such low-level mistakes!

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

thinkphp view model 3 tables joint query

It is not recommended to perform aggregation operations on connections, as it is easy to cause problems. Generally, the user's consumption amount is directly synchronized. In other words, there is a separate user consumption table, and the value of this field is increased when the user consumes. .

Or write your sql room order and catering order separately, otherwise it will only be nested, which seems not necessary

Problems using thinkphp M method

What you passed is "RJ1". The M method M ("RJ1") passes the class name. Thinkphp will convert the class name into a table name when querying. The rule is the table prefix + _uppercase letters and lowercase letters
+ _uppercase letters and lowercase letters. For example, if AbcDef is converted into a table name, it is caiyy_abc_def. If it is changed to lowercase, there will be no problem. action="/Index
/ addsoft/rj1", there is another error in the program:
$Form =M($soft);$Form->create();
This should be D($soft); only objects created by the D function There is a create method.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/903485.htmlTechArticlethinkphp view model query prompt ERR: 1146: Solution to Table 'db.pr_order_view' doesn't exist, vieworder The example in this article describes the thinkphp view model query failure prompt: ERR: 1146:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn