Backend Extensions: additional fields
9. Februar 2008 von urban |
From a developers view the reason why I like the Oxid eShop is, that quite a view things are very easy to customize. One of these things is adding your own fields to tables in the database and make them editable through the backend interface. Here is how to do it:
Let’s say you want to add a field MY_FIELD to the oxarticles table and want to put a new form field into the main article menue to edit the content of the new table field.
First of course add the field to the database using phpMyAdmin or whatever tool you use for your db-administration. Now look for the template which has to be extended for adding the form field. If you don’t know how to find the right template, do the following:
Open the admin interface, open menue Administer Products -> Products and klick on an article of the list at the top of the page. Now, if you move your mouse over the tabs (Main, Extended, Inventory etc.) have a look at the status bar at the bottom of your browser. There you will see something like this: javascript:ChangeEditBar( ‘article_main’, 0); – which shows you the name of the PHP-class – and file – which is called by clicking on that tab. The templates are named the same. So if you see ‘article_main’ you cann be sure that a.) the used class is called article_main.php and the according template is called article_main.tpl (I assume that the locations of admin view classes and templates is known).
Well, so open the template article_main.tpl with an editor. If your new field is a text-field, look for a similar field in the already existend code. For example you could take the searchkeys-field:
<tr>
<td class="edittext">
[{ oxmultilang ident="ARTICLE_MAIN__OXARTICLES__OXSEARCHKEYS_RR" }]
</td>
<td class="edittext">
<input type="text" class="editinput" size="32"
maxlength="[{$edit->oxarticles__oxsearchkeys->fldmax_length}]"
name="editval[oxarticles__oxsearchkeys]"
value="[{$edit->oxarticles__oxsearchkeys->value}]">
</td>
</tr>
(This is an example of the OXID EE code – PE is slightly different but the differences are obvious.)
So now just copy that table-row an paste it to the end of the table before the section with the submit button. Afterwards changed the used variables to the names of your table field:
<tr>
<td class="edittext">
Title of my field
</td>
<td class="edittext">
<input type="text" class="editinput" size="32"
maxlength="[{$edit->oxarticles__my_field->fldmax_length}]"
name="editval[oxarticles__my_field]"
value="[{$edit->oxarticles__my_field->value}]">
</td>
</tr>
Now you can fill out your new field and save the content to the database.




Uff … – although I found a useful plugin for code-highlighting – writing php- or html-code inside posts in wordpress is a real pain! It works for the first save-klick, but if you have to edit something in the post, parts of the code are gone.
If anybody knows a nother plugin or a better way to solve this – please let me know!!
Sorry for not being of any real help! But since I am a little german sadist and enjoy the English written by Germans I can contribute to your aim “to edit something in the post”. Make it “quite a few things” rather than “quite a view things”. Again apologizing for being cheeky… Normally you have to write normally instead of normaly and so on…
@Fritz
.
No Problem at all. I do appreciate your comment cause I am willing to learn and to improve. The “view/few” stuff was a sort of blackout thing (probably caused by using “view” in the first part of the sentence), but the “Normally” thing was a real mistake and I’ll try to keep that in mind.
Written English has never been one of my favourites – so if you keep on reading the stuff in this category here you probably will enjoy allthough you might not understand all of the issues.
For further corrections of my bad English I suggest you to write me emails – so I am not blamed in public and thematic discussion will not be disturbed (if there is one … some time …)
Cheers!
urban
hey! thank you for your post! I have a strange problem… as soon as I add a field to the oxarticles table (e.g. OXAUTHOR), the article list won´t show up anymore in the backend. I can add articles and they are saved to the database, but the article list in the backend is gone. I use Community Edition 4.5.4_39463. Have you ever seen a behavior like this? cheers,
Florian
Did you update the views? Backend -> Service -> Tools.
Always if you change tables which do have views, you have to update the views. – By the way: you should NOT name your own table-fields something like “OX….” – the prefix “OX” is reserved for oxid original fields. Imagine if with one of the next updates OXID itself introduces a new field called “OXAUTHOR” … – you will get into big trouble.