This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

table prefix and phpName in schema.xml

Social code snippet repository

table prefix and phpName in schema.xml

by simo » Thu Jun 05, 2008 1:25 pm

Hi all,

I wrote few lines of code to remove table prefix and automatically provides phpName attribute to tables on schema.xml file, respecting the CamelCase format.

You just have to provide the prefix, the source xml file and the generated xml file (if different - not compulsory).

Code: Select all
$prefix = 'prefix_';
$filePath = 'way\to\your\xml\file';
$fileSave = 'way\to\the\generated\xml\file'; # not compulsory

function removePrefix ($string) {
  $prefix = $GLOBALS['prefix'];

  $string = str_replace($prefix, '', $string);
  $arr = split('_', $string);
  $name = '';
  foreach($arr as $row) {
    $name .= ucfirst($row);

  return $name;


if (file_exists($filePath)) {

  $xml =simplexml_load_file($filePath);

  foreach($xml->xpath('//table') as $item) {
    $attrs = $item->attributes();
    $phpName = removePrefix ($attrs['name']);
    $item->addAttribute('phpName', $phpName);

  if(isset($fileSave) && $fileSave != '') {
    $xmlFile = $fileSave;
  } else {
    $xmlFile = $filePath;

} else {
  exit('Failed to open file : '. $filePath);

Hope i'm not re-inventing the wheel and it will be usefull to you!

I guess the message has to be switched to another category.. sorry for that.
(845 Bytes) Downloaded 614 times
Posts: 41
Joined: Sat May 31, 2008 8:09 am
Location: Paris