简体   繁体   中英

Joomla mysql tables.php syntax

Building a component, version 1.5 (gonna be cut loose soon, I know, but it's what I need to work with.)

Issue with the /admin/tables/mycom.php file. (In which mycom is whatever the component name is)

I'm not following the use of this file. From reading the walkthrough, it's creating a table class that extends JTables.

Now, some of the DB column names I'm using have 'space' characters in them. ie, 'field 1' instead of 'field1' (don't ask me, it's not my data.)

The sytax for identify these fiels is:

 $myfield = null

It says these reference your fields in the mySQL table, but my field names include space which wouldn't work with this syntax.

Any help understanding this class, it's php file and what it's use is would be much appreciated.

By creating a JTable class for your table most of the code for editing your table is done for you. I suggest you familiarize yourself with JTable in the Joomla library so you know what functions are pre-written for you that you can use and override.

As to the issue of your DB column name having spaces... well to be honest it's just a bad idea. Here are some MySQL naming convention best practices for you....

  • always use lowercase with underscores instead of CamelCase. Goes for both the table and column names. (first_name instead of FirstName, address_1 instead of Address1
  • every table should have an "id" column as the primary key, don't call it UserID or anything else
  • the table name should be plural (profiles, supports, etc.)
  • foreign keys should have the singular name of the related table followed by underscore id. For example: "profile_id" or "support_id".

If you can I would recommend you do some ALTER TABLE updates to the MySQL eg

ALTER TABLE `#__example` CHANGE `Field 1` `field_1` VARCHAR(50) NOT NULL DEFAULT 'empty';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM