Yii Framework Forum: [EXTENSION] mwbmodelcommand discussion thread - Yii Framework Forum

Jump to content

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] mwbmodelcommand discussion thread Rate Topic: -----

#21 User is offline   unikly 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-January 09

Posted 11 February 2009 - 03:47 AM

Hi Ramin,

Could you confirm what happens if you only put in the mwbmodel in the yii shell and hit enter?
0

#22 User is offline   cass 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 59
  • Joined: 01-February 09
  • Location:London, UK

Posted 11 February 2009 - 02:31 PM

Hi Unikly,

It was my php_zip.dll not enabled on PHP's CLI mode, hence not registering the stream zip wrapper. :) Apparently WAMP uses two different php.ini files, one for CLI and another for Apache.
I got to use your code now and it looks very good. Well done! Will experiment more and give you feedback later. Many thanks for your efforts.

Cass
0

#23 User is offline   Ramin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 08-February 09

Posted 12 February 2009 - 09:55 PM

Hi Unikly,
I'll see the following message when I only put in the wmbmodel in the yii shell and hit enter.

>> mwbmodel
Error: wmb file name is required.
Usage: wmbmodel <mwb-file>
This command generates model classes with relationships parsed from MySQL workbe
nch mwb file.
* mwb-file: required, mwb file.
0

#24 User is offline   unikly 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-January 09

Posted 12 February 2009 - 10:30 PM

Hi Ramin,

If you can successfully launch the command, and see the usage prompt, then all I can think of is your PHP configuration, please check you have SimpleXML and Zip enabled. Please check.

cheers
0

#25 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 680
  • Joined: 29-November 08
  • Location:Paris, France

Posted 13 February 2009 - 11:57 AM

Hi,
if I may add that under Windows console, backslahes should be replaced by slashes, or you'll get the following error message :

simplexml_load_file(zip://e:%5Cschema-2.mwb#document.mwb.xml): failed to open stream: No such file or directory


So you should type :

>>  mwbmodel e:/schema-2.mwb


(unless I missed something ;) )

Great command ! thank you ...

8)
0

#26 User is offline   Ramin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 08-February 09

Posted 13 February 2009 - 10:44 PM

Hi Unikly,

I've enabled the zip extension and it worked! Thank you so much! Great command.
0

#27 User is offline   unikly 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-January 09

Posted 16 February 2009 - 08:09 AM

Thanks Raoul for your suggestion, we'll surely implement that in the next release.

So it would work better for different platforms.

cheers :)

PS: Minor bug fix version R2464 has the patch for this \ backslash problem.
0

#28 User is offline   bulareanuadrian 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 17-February 09

Posted 17 February 2009 - 05:51 AM

Hi,

Can somebody help me with this?

Quote

C:\wamp\www\CondalTek\protected>yiic mwbmodel c:\CondalTek.mwb

exception 'CDbException' with message 'CDbConnection.connectionString cannot be

empty.' in C:\wamp\www\yii\framework\db\CDbConnection.php:223

Stack trace:

#0 C:\wamp\www\yii\framework\db\CDbConnection.php(208): CDbConnection->open()

#1 C:\wamp\www\yii\framework\db\CDbConnection.php(187): CDbConnection->setActive

(true)

#2 C:\wamp\www\yii\framework\base\CApplication.php(734): CDbConnection->init()

#3 C:\wamp\www\yii\framework\base\CApplication.php(385): CApplication->getCompon

ent('db')

#4 C:\wamp\www\CondalTek\protected\commands\mwbModelCommand.php(148): CApplicati

on->getDb()

#5 [internal function]: mwbModelCommand->generateModel('C:\wamp\www\yii...', Arr

ay)

#6 C:\wamp\www\yii\framework\console\CConsoleCommand.php(116): call_user_func(Ar

ray, 'C:\wamp\www\yii...', Array)

#7 C:\wamp\www\CondalTek\protected\commands\mwbModelCommand.php(56): CConsoleCom

mand->copyFiles(Array)

#8 C:\wamp\www\yii\framework\console\CConsoleCommandRunner.php(62): mwbModelComm

and->run(Array)

#9 C:\wamp\www\yii\framework\console\CConsoleApplication.php(88): CConsoleComman

dRunner->run(Array)

#10 C:\wamp\www\yii\framework\base\CApplication.php(170): CConsoleApplication->p

rocessRequest()

#11 C:\wamp\www\yii\framework\yiic.php(30): CApplication->run()

#12 C:\wamp\www\CondalTek\protected\yiic.php(7): require_once('C:\wamp\www\yii..

.')

#13 C:\wamp\www\CondalTek\protected\yiic(4): require_once('C:\wamp\www\Con...')

#14 {main}

C:\wamp\www\CondalTek\protected>



My db array from main.php:

Quote

'db'=>array(

'class'=>'CDbConnection',

            'connectionString'=>'mysql:host=localhost;dbname=CondalTek',

            'username'=>'root',

            'password'=>'',

),

0

#29 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 17 February 2009 - 07:13 AM

Exit yiic shell and re-enter after your config is changed.
0

#30 User is offline   unikly 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 21-January 09

Posted 17 February 2009 - 03:57 PM

Hi bulareanuadrian,

You should start yiic shell from the directory that contains the project dispatch file (where index.php is), not from the protected folder.

Try again please!
0

#31 User is offline   agentshark 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 04-March 09

Posted 04 March 2009 - 07:34 AM

I used the extension and using the model straight out the box with crud commands fail. only delete works.

yiic model parses metadata and fills out the rules() function.
0

#32 User is offline   yuyiiyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-March 09

Posted 04 March 2009 - 01:50 PM

Hi,
i try to get mwbmodel working but i get in problem
help me please!

D:\xampp\htdocs\reportplanete\protected>yiic shell d:\xampp\htdocs\reportplanete
\index.php
Yii Interactive Tool v1.0
Please type 'help' for help. Type 'exit' to quit.
>> help
At the prompt, you may enter a PHP statement or one of the following commands:
- controller
- crud
- help
- model
- module
- mwbmodel
Type 'help <command-name>' for details about a command.

>> help mwbmodel
Usage: wmbmodel <mwb-file>
This command generates model classes with relationships parsed from MySQL workbe
nch mwb file.
* mwb-file: required, mwb file.
>> mwbmodel d:\xampp\htdocs\gen\vertedb.mwb
<!DOCTYPE html PUBLIC
        "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>
PHP Error</title>

<style type="text/css">
/*<![CDATA[*/
body {font-family:"Verdana";font-weight:normal;color:black;background-color:whit
e;}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
p {font-family:"Verdana";font-size:9pt;}
pre {font-family:"Lucida Console";font-size:10pt;}
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
.message {color: maroon;}
.source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffe
e;}
.error {background-color: #ffeeee;}
/*]]>*/
</style>
</head>

<body>
<h1>PHP Error</h1>

<h3>Description</h3>
<p class="message">
Invalid argument supplied for foreach()</p>

<h3>Source File</h3>
<p>
D:\xampp\htdocs\yii\framework\cli\commands\shell\mwbModelCommand.php(99)</p>

<div class="source">
<pre>
00087:        //get mysql Schema
00088:        $ms = getNodeByAttr($mc-&gt;value[0], &#039;content-struct-name&#
039;, &#039;db.mysql.Schema&#039;);
00089:        $mysqlSchema = getNodeByAttr($ms-&gt;value[0], &#039;struct-name&
#039;, &#039;db.mysql.Schema&#039;);
00090:
00091:
00092:        //get mysql Table
00093:        $mt = getNodeByAttr($mysqlSchema-&gt;value[0], &#039;content-stru
ct-name&#039;, &#039;db.mysql.Table&#039;);
00094:        $tables = getNodeByAttr($mt-&gt;value[0], &#039;struct-name&#039;
, &#039;db.mysql.Table&#039;);
00095:
00096:        $mwbtbls = array();
00097:        $mwbFKs = array();
00098:
<div class="error">00099:        foreach($tables-&gt;value as &amp;$tab){
</div>00100:            $tid = (string) $tab-&gt;attributes()-&gt;id;
00101:            $mwbtbls[$tid] = new mwbTable($tab);
00102:
00103:            $fks = getNodeByAttr($tab, &#039;content-struct-name&#039;, &
#039;db.mysql.ForeignKey&#039;);
00104:            foreach($fks-&gt;value[0]-&gt;children() as $fk) {
00105:                $f = new mwbFK($fk, $tid);
00106:                if (!empty($f-&gt;RefTid)) $mwbFKs[] = $f;
00107:            }
00108:        }
00109:
00110:        // translate ids in fk to actual names
00111:        foreach($mwbFKs as &amp;$fk) {
</pre>
</div><!-- end of source -->

<h3>Stack Trace</h3>
<div class="callstack">
<pre>
#0 D:\xampp\htdocs\yii\framework\cli\commands\shell\mwbModelCommand.php(45): mwb
ModelCommand-&gt;parsemwb()
#1 D:\xampp\htdocs\yii\framework\cli\commands\ShellCommand.php(99): mwbModelComm
and-&gt;run()
#2 D:\xampp\htdocs\yii\framework\cli\commands\ShellCommand.php(79): ShellCommand
-&gt;runShell()
#3 D:\xampp\htdocs\yii\framework\console\CConsoleCommandRunner.php(62): ShellCom
mand-&gt;run()
#4 D:\xampp\htdocs\yii\framework\console\CConsoleApplication.php(88): CConsoleCo
mmandRunner-&gt;run()
#5 D:\xampp\htdocs\yii\framework\base\CApplication.php(170): CConsoleApplication
-&gt;processRequest()
#6 D:\xampp\htdocs\yii\framework\yiic.php(30): CConsoleApplication-&gt;run()
#7 D:\xampp\htdocs\reportplanete\protected\yiic.php(7): require_once()
</pre>
</div><!-- end of callstack -->

<div class="version">
2009-03-04 19:43:58 <a href="http://www.yiiframework.com/">Yii Framework</a>/1.0
.3</div>
</body>
</html>
D:\xampp\htdocs\reportplanete\protected>

Thanks
0

#33 User is offline   yuyiiyii 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 04-March 09

Posted 05 March 2009 - 01:59 PM

finaly, it works !!
0

#34 User is offline   roo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-December 08

Posted 05 March 2009 - 02:31 PM

Quote

finaly, it works !!


What did you do to get it working?  I have same error.
0

#35 User is offline   roo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-December 08

Posted 09 March 2009 - 06:15 PM

Can anybody help with this?  I'm not sure how you are parsing the xml.  It is opening, unzipping and reading my mwb file (I added some var_dumps).
I'm using mysqlworkbench 5.0.30 OSS

nalberda@Sol20070001:/var/www/testdrive$ ./protected/yiic shell
Yii Interactive Tool v1.0                                     
Please type 'help' for help. Type 'exit' to quit.             
>> mwbmodel fatbastard.mwb                                   
<!DOCTYPE html PUBLIC                                         
        "-//W3C//DTD XHTML 1.0 Transitional//EN"             
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>                                                           
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>                                                           
PHP Error</title>                                                 

<style type="text/css">
/*<![CDATA[*/         
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }         
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }       
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}                       
p {font-family:"Verdana";font-size:9pt;}                                         
pre {font-family:"Lucida Console";font-size:10pt;}                               
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}               
.message {color: maroon;}                                                         
.source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;}
.error {background-color: #ffeeee;}                                               
/*]]>*/                                                                           
</style>                                                                         
</head>                                                                           

<body>
<h1>PHP Error</h1>

<h3>Description</h3>
<p class="message">
Invalid argument supplied for foreach()</p>

<h3>Source File</h3>
<p>               
/var/www/yii-1.0.3.r780/framework/cli/commands/shell/mwbModelCommand.php(96)</p>

<div class="source">
<pre>             
00084:        //get mysql Schema
00085:        $ms = getNodeByAttr($mc-&gt;value[0], &#039;content-struct-name&#039;, &#039;db.mysql.Schema&#039;);
00086:        $mysqlSchema = getNodeByAttr($ms-&gt;value[0], &#039;struct-name&#039;, &#039;db.mysql.Schema&#039;);
00087:                                                                                                             
00088:                                                                                                             
00089:        //get mysql Table                                                                                   
00090:        $mt = getNodeByAttr($mysqlSchema-&gt;value[0], &#039;content-struct-name&#039;, &#039;db.mysql.Table&#039;);
00091:        var_dump($mt);
00092:        $tables = getNodeByAttr($mt-&gt;value[0], &#039;struct-name&#039;, &#039;db.mysql.Table&#039;);
00093:        var_dump($tables);
00094:        $mwbtbls = array();
00095:        $mwbFKs = array();
<div class="error">00096:        foreach($tables-&gt;value as &amp;$tab){
</div>00097:            $tid = (string) $tab-&gt;attributes()-&gt;id;
00098:            $mwbtbls[$tid] = new mwbTable($tab);
00099:
00100:            $fks = getNodeByAttr($tab, &#039;content-struct-name&#039;, &#039;db.mysql.ForeignKey&#039;);
00101:            foreach($fks-&gt;value[0]-&gt;children() as $fk) {
00102:                $f = new mwbFK($fk, $tid);
00103:                if (!empty($f-&gt;RefTid)) $mwbFKs[] = $f;
00104:            }
00105:        }
00106:
00107:        // translate ids in fk to actual names
00108:        foreach($mwbFKs as &amp;$fk) {
</pre>
</div><!-- end of source -->

<h3>Stack Trace</h3>
<div class="callstack">
<pre>
#0 /var/www/yii-1.0.3.r780/framework/cli/commands/shell/mwbModelCommand.php(45): mwbModelCommand-&gt;parsemwb()
#1 /var/www/yii-1.0.3.r780/framework/cli/commands/ShellCommand.php(99): mwbModelCommand-&gt;run()
#2 /var/www/yii-1.0.3.r780/framework/cli/commands/ShellCommand.php(79): ShellCommand-&gt;runShell()
#3 /var/www/yii-1.0.3.r780/framework/console/CConsoleCommandRunner.php(62): ShellCommand-&gt;run()
#4 /var/www/yii-1.0.3.r780/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner-&gt;run()
#5 /var/www/yii-1.0.3.r780/framework/base/CApplication.php(170): CConsoleApplication-&gt;processRequest()
#6 /var/www/yii-1.0.3.r780/framework/yiic.php(30): CConsoleApplication-&gt;run()
#7 /var/www/testdrive/protected/yiic.php(7): require_once()
#8 /var/www/testdrive/protected/yiic(4): require_once()
</pre>
</div><!-- end of callstack -->

<div class="version">
2009-03-09 17:17:44 <a href="http://www.yiiframework.com/">Yii Framework</a>/1.0.3</div>
</body>
</html>nalberda@Sol20070001:/var/www/testdrive$

0

#36 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 24 March 2009 - 11:42 AM

work fine here...

any sampl aabout how to use relationship class to view files


public function relations()
{
return array(
'grupo'=>array(self::BELONGS_TO,'grupo','grupo_id'),
);
}


public function relations()
{
return array(
'usuario'=>array(self::HAS_MANY,'usuario','grupo_id'),
);
}



regards

0

#37 User is offline   luke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 30-March 09

Posted 13 April 2009 - 01:16 AM

I have been using this extension and it saves me a lot of coding which is great. So thanks to all those involved in putting this extension together.

I would love to see this extension extend to be able to translate 'views' in a mwb file. I know there are extensions out there for propel and doctrine to do this, would be great if we could produce same thing for Yii.

Cheers and thanks again
0

#38 User is offline   will 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 179
  • Joined: 21-March 09

Posted 13 April 2009 - 02:47 AM

Mwbmodel is a great yii extension, which could save lots of time to deal with models.
However, I want to make a suggestion here, it would be better to generate a camel case class name for each table, so that we can keep class name convention in our code.
for example:

for 'user_role' table, should generate class name
UserRole
while put the following code in model class:



0

#39 User is offline   thomas.mery 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 04-January 09

Posted 17 April 2009 - 02:27 AM

Hello,

and thank you for this

I am trying to use it as it will be really helpful.

I have a question regarding the M:M relationship

@unikly you said

Quote

For example, you have Table1 and Table2, and they are in M:M relationship, ie. you have a composite TableC which contains only the primary keys from Table1 and Table2 (other wise 1:M and M:1 will take place). When the classes are generated,



In Table1, it would have something like:

'Table2'=>array(self::MANY_MANY, 'Table1', 'TableC(t1ID, t2ID)')



Similarly in Table2 you get,

'Table1'=>array(self::MANY_MANY, 'Table2', 'TableC(t1ID, t2ID)')



It also generates a class for TableC with,

'Table1'=>array(self::BELONGS_TO, 'Table1', 't1ID'),

'Table2'=>array(self::BELONGS_TO, 'Table2', 't2ID')


But looking at the docs and the schema in the blog tuto I thought it would have to be  :


In Table1
'Table2'=>array(self::MANY_MANY, 'Table1', 'TableC(TableC_t1ID, TableC_t2ID)')

Table2
'Table1'=>array(self::MANY_MANY, 'Table2', 'TableC(TableC_t1ID, TableC_t2ID)')


where TableC has a composite PK of : TableC_t1ID, TableC_t2ID

since in the blog tuto for instance the relaionship that is recommended for : Post M:M Tag

is :

'tagFilter'=>array(self::MANY_MANY, 'Tag', 'PostTag(postId, tagId)'


where the join table PK is (postId, tagId)

whereas the extension generates :

'Tag'=>array(self::MANY_MANY,'Tag','PostTag(id,id)'),


actually using the REFERENCES in the CONSTRAINT statement : (id,id)

Am I missing something ?

I am no sql expert and am pretty new to Yii so maybe I did miss something

thank you if you find time to answer this
0

#40 User is offline   imortis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 16-April 09
  • Location:Poland - Wrocław

Posted 28 April 2009 - 02:29 PM

It's a great extension. I've used it under linux server and it worked fine for me, but when I am switching to do some code locally on my laptop something is going wrong... After using "mwbmodel model.mwb" command something crashes - nothing appears in console - only popup error "CLI stopped working".

My specs:
Xampp Version 1.7.1 for Windows
Yii framework 1.0.4

Any help please? ;)
0

Share this topic:


  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users