Questions about ZF table model creation

Source: Internet
Author: User
Online help for creating ZF table models & nbsp; in the ZF Framework & nbsp; create a table Model & nbsp; however, there are two primary keys in the table (which are key combinations) & nbsp; how to change the table model? & nbsp ;??????? Class & nbsp; IndentdetailModel & nbsp; extends & nb ZF table model creation online
For help, I have created a table model in the ZF framework. but there are two primary keys in the table (which are key combinations). how can I change the table model ???????

class IndentdetailModel extends Zend_Db_Table{
protected $_name="indentdetail";
protected $_primary="indentnumber";


Table structure:

How can I create a table model for such a table? mainly protected $ _ primary = ?? I don't know how to share it here:
------ Solution --------------------
Today, I took the time to try out your questions. I got some conclusions and shared them with you.

First, $ _ primary is a member variable of the table model. it must be reconstructed when building the table model.
This variable can be a string or an array. whether it is a string or an array depends on whether your data table has a primary key or multiple primary keys.
When the data table has only one primary key, $ _ primary is initialized with a string.
When the data table contains multiple fields as the primary key, you need to use an array to initialize $ _ primary, and the array length is the same as the number of primary keys.

I still use the find () method for testing.

Because $ _ primary may be a string or an array, the parameter list also has multiple forms when using the find method.

Let me first talk about the case where the $ _ primary variable is a string, that is, the data table has only one primary key.
In this case, there is only one primary key. you can use the find () method to find one or more rows in the data table.
When you want to query a row, you can directly pass the string to the find function.
To query multiple rows, you need to write the fields to be queried into an array and pass the array into the find () method.

Both cases are well understood. The $ _ primary variable is an array, that is, the data table has multiple primary keys.

In this case, there are multiple primary keys. you can use the find () method to find one or more rows in the data table.
To query a row, you need to input the number of primary key parameters to the find () function. for example, if you have two primary keys, you need to pass the values to be queried of these two primary keys as parameters to the find () method, the sequence must be consistent with the array sequence during $ _ primary initialization.
To query multiple rows, you need to input an array of the number of primary keys to the find () function. for example, if you have two primary keys, you need to create two arrays and pass them as parameters to find (). The first array stores all values of the first primary key to be queried, the second array stores all values of the second primary key to be queried. it must be emphasized that the length of the two arrays must be the same, that is, the number of rows you are trying to query (the reason for "trying" is that it may not exist ), the number of arrays is the number of primary keys.

For your convenience, I will show you the examples I have made.

My student table structure:
Both sid and sname are set as the primary key, so two '001' will appear '.

+ ----- + -------- + ----- +

------ Solution --------------------
Sid
------ Solution --------------------
Sname
------ Solution --------------------
Sex
------ Solution --------------------

+ ----- + -------- + ----- +

------ Solution --------------------
001
------ Solution --------------------
Parker
------ Solution --------------------
Male
------ Solution --------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.