Preliminary Tutorial for DBDesigner2Cake

Hi!

 I am preparing yet a more complete tutorial, but as appeared some demands on how to use dbdesigner2cake I decided to release a preliminary tutorial.

 Well, I assume you know how to use DBDesigner, your database of choice and some shell operation. I assume also that you have unpacked CakePHP’s files into a directory and had it configured, and the tables drawn in DBDesigner are stored in database too.

Let us take an ER diagram like this:

ER Modelling by DBDesigner

 Please note that the relationships created fields on the tables, for instance, users relates to posts through “user_id” field. You will also notice that DBDesigner create fields in plural instead of singular (tags_id versus tag_id), thus you should rename then to singular flexion. Also we have both a hasMany relationship and a hasAndBelongToMany relationship.

  Unpack CakePHP’s zip file, put dbdesigner2cake.php and save DBDesigner’s XML file in the same root directory like this:

# find -maxdepth 1
.
./sql
./app
./cake
./docs
./index.php
./vendors
./.htaccess
./dbdesigner2cake.php
./modelling.xml <– the ER diagram saved as XML by DBDesigner.

 Now you should generate the scripts using dbdesigner2cake.php

# php dbdesigner2cake.php modelling.xml
Scaffolding Post — done
Scaffolding User — done
Scaffolding Tag — done
Skipping PostsTag - HABTM table.
Done

Well, point your browser either to
http://yourhost/application/post/ or
http://yourhost/application/user/ or
http://yourhost/application/tag/

And you’ll see that your application is working (at least in theory).

12 Responses to “Preliminary Tutorial for DBDesigner2Cake”

  1. Yanoshin Says:

    This script you wrote is GREAT! I got so impressed, and that makes our first move to build CakePHP stuffs very quick.

    if it’s ok, I’ll translate manuals or tutorials into Japanese language(
    my native tougue). how about it?

  2. Dérico Filho Says:

    Hi Yanoshin!

    Feel free to translate whatever you wish, just do as things are done: give the credits and tell me what you did so we can crosslink each other.

    Good luck, I hope you enjoy the tool as much as I did.

    Bye

  3. Osni Passos Says:

    Parabéns, testei aqui e funcionou como o previsto, facilida na hora dos testes iniciais.
    Pergunta: tem pretenções de melhora-lo com os seguinte itens:
    -Opção de geração completa (Não-scafold);
    -plugin no DBdesigner;
    -Validação de dados baseado no conteudo.
    -gerar um menu no index.

    Abraços e bom trabalho.

  4. Dérico Filho Says:

    Oi Osni!

    Espero que você goste da ferramenta tanto quanto eu!

    Pretendo aprimorá-lo:
    - Geração de código scaffold sem usar a variável scaffold: Está sim nos meus planos, devo caminhar para fazer a integração com o Bake.php - só que estou esperando a versão 1.2 sair de alpha para isto.
    - Um plugin para o DBDesigner? O que vc sugere? não consigo imaginar isto.
    - Validação baseada no conteúdo está feita, e é um switch de linha de comando. Executa com a opção -h que vc verá a opção de validação.
    - Pretendo num release futuro fazer um shell, uma opção interativa de operação - mas quero fazer a integração com o Bake.php primeiro.

    Abraços!

  5. Osni Passos Says:

    Opa,

    Tentei usar a opção -wv mas não encontrei onde está a validação dentro do código gerado, na verdade não encontrei nada diferente, onde está? Imaginei que seria gerado algo como:

    var $validate = array(

    ‘login’ => ‘/[a-z0-9\_\-]{3,}$/i’,

    ‘password’ => VALID_NOT_EMPTY,

    ‘email’ => VALID_EMAIL,

    ‘born’ => VALID_NUMBER

    Quanto ao plugin, imaginei que pudesse ser feito dentro do próprio dbdesigner no menu de plugins, digamos em um botão gera-se tudo e desse mais opções, como se fosse uma interface para a linha de comando. mas não encontrei nada na documentação para isso.

    Abraços e bom trabalho, gostei bastante da idéia de usar os modelos do dbdesigner ara gerar o código basico para o cake.

    Abraços

  6. Dérico Filho Says:

    Oi Osni!

    Vc encontrou um bug, e eu resolvi. A versão corrigida está disponível na página de download:

    http://www.cirello.org/dbdesigner2cake/download.html

    Abraços.

  7. Entradas en las blogosferas.18 - Carrero Bitácora de los Hermanos Carrero, David Carrero Fernández-Baillo y Jaime Carrero Fernández-Baillo. Says:

    […] Tutorial preliminar para DBDesigner2Cake. […]

  8. Wahoo Says:

    Thank you for sharing!

  9. naxis Says:

    thnak you very must for this great program.I’m having a lot of fun with it.
    I would like to ask two things.
    1. You wrote that we must change the FK from tags_id to tag_id is that in the xml file DBDesigner vomits?

    2. Can we make validation?

    3. Can the program create the views files?

    thank you

  10. naxis Says:

    I’m getting this warning

    PHP Notice: Undefined index: categories in /var/www/html/cake_1.2/dbdesigner2cake.php on line 293

  11. Dérico Filho Says:

    Hi Naxis,

    I will begin from the top.

    1. You can change the FK name by double-clicking in the relationship line. It’ll appear a dialogue with a FK table on which you’ll be able to rename it.

    2. The dbdesigner2cake has a validation function, just add the -wv (–with-validation) parameters in invokation parameters.

    3. When DBDesigner2Cake detects CakePHP 1.2, it’ll offer you the option -wb (–with-bake), that it uses to generate Controller and View source code using CakePHP Bake’s script.

    Secondly, you told about an error I need more information, such which DBDesigner2Cake revision you are using, the CakePHP version you are using and also - if possible - the XML file which you used to produce the output.

    Thanks

  12. David Bennett Says:

    Had trouble getting this running until I figured out that the latest version of the script (1.0.6) and XML schema should be placed in a directory under the \app directory:

    $CAKE_CORE_INCLUDE_PATH = dirname(dirname(dirname(__FILE__)));
    $APP = basename(dirname(dirname(__FILE__)));

    Now I am getting a different error:

    C:\projects\xxx\wwwroot\app\dbdesigner2cake>\xampp\php\php dbdesigner2cake.php schema.xml
    dbdesigner2cake.php: CakePHP 1.2.0.7692 RC3 detected.

    Warning: require(LIBSset.php): failed to open stream: No such file or directory in C:\projects\xxx\wwwroot\cake\libs\inflector.php on line 37

    Fatal error: require(): Failed opening required ‘LIBSset.php’ (include_path=’.;C:\xampp\php\pear\’) in C:\projects\xxx\wwwroot\cake\libs\inflector.php on line 37

    What is LIBSset.php?

Leave a Reply