Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement an equipment system in CakePHP
    primarykey
    data
    text
    <p>I'm attempting to create a CakePHP based web game mostly for practice as well as for the fun of it, but am running into a conundrum trying to figure out an equipment system.</p> <p>I have an Items table that contains all the possible information about an item, including an item_type field that contains an integer value determining what the item type is, and resulting, which information about the item to use.</p> <p>i.e. item_type = '1' means that the item is a hat to use, which means that only power, price, bonuses, and requirements are necessary information. This all works fine.</p> <p>I also have an items_users HABTM table set up in order to store all the currently owned items that each player has, this is also working fine.</p> <p>What I'm trying to figure out is how an equipment system would work. I first thought about an equips table such as:</p> <pre><code> CREATE TABLE `aevum_tf`.`equips` ( `id` INT NOT NULL , `user_id` INT NOT NULL , `hat_id` INT NOT NULL , `wep_id` INT NOT NULL , `offhand_id` INT NOT NULL , `pants_id` INT NOT NULL , `acca_id` INT NOT NULL , `accb_id` INT NOT NULL , `accc_id` INT NOT NULL , `shirt_id` INT NOT NULL , `created` DATETIME NOT NULL , `modified` DATETIME NOT NULL , PRIMARY KEY ( `id` ) , UNIQUE ( `user_id` ) ) ENGINE = InnoDB </code></pre> <p>The only problem with using a system like this is that CakePHP does not support multiple foreign keys for a model.</p> <p>Does anyone have any ideas as to how to implement such a system?</p> <p><em>EDIT</em> The existing HABTM table of items_users is used to store which items a user currently owns. Every time a user acquires a new item, it's id and the user's id is stored in the items_users table. I'm just trying to figure out how to implement an equipment system.</p> <p>By doesn't support multiple foreign keys, I mean CakePHP doesn't natively support multiple foreign keys from one table in another table. My example equips table has 8 foreign keys, all pointing to item_id's.</p> <p>see: <a href="https://trac.cakephp.org/ticket/1923" rel="nofollow noreferrer">https://trac.cakephp.org/ticket/1923</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload