且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在cakephp表上创建按钮以创建新表?

更新时间:2023-02-03 17:20:34

如果我正确理解,您希望将一个客户链接到一个商店位置(或者可能是多个位置)。

If I understand correctly you want to linked one client to one shop location (or maybe many location).

第一种方法是一对多。 (客户端属于位置,而位置属于hashas许多客户端)您需要与客户端创建表,并放入新列,如 location_id 。然后只需为客户端设置多个位置之一(在编辑中或将postButton与location_id和client_id配合使用)。

First way is one to Many. (client belongs to location and location hasMany clients) You need to create table with you clients and put new column like location_id. Then simply set one of many location to client (in edit or use postButton with location_id and client_id).

第二种方法是多对多的。这意味着许多客户端属于许多位置,许多位置属于许多客户端。喜欢文章中的标签。您需要创建三个表。一个与客户,一个与位置,一个与客户连接在一起。

Secondly way is many to many. That means many clients belongs to many locations and many locations belongs to many clients. Like tags in articles. You need to create three tables. One with clients, One with locations and One to connect it together.

通过这种方式,客户表和位置表没有任何其他列可直接指向自己(例如location_id或client_id)。您需要制作第三个名称为 clients_locations 的表,并添加带有客户表和位置表 ID的行。简单示例:

In this way Clients Table and Location Table dont't have any additional columns to direct to themselfs (like location_id or client_id). You need to make third table with name clients_locations and add colmuns with ID of Client Table and Location Table. Simple example:

   +--------+-------------+-----------+
   | id.    | location_id | client_id |
   +--------+-------------+-----------+
   |   1    |       3     |    10     |
   +--------+-------------+-----------+
   |   2    |       4     |     3     |
   +--------+-------------+-----------+
   |   3    |       7     |     9     |
   +--------+-------------+-----------+
   |   4    |       4     |    40     |
   +--------+-------------+-----------+

在Cakephp中,其名称为属于Tony。

In Cakephp its name as BelongsToMany.