大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > ASP.NET技巧 > CodeSmith 使用教程(3): 自动生成Yii Framework ActiveRecord

CodeSmith 使用教程(3): 自动生成Yii Framework ActiveRecord(2)

关键词:CodeSmith使用教程  阅读(1789) 赞(13)

[摘要]本文主要介绍CodeSmith 使用教程(3): 自动生成Yii Framework ActiveRecord,希望对你解决相关问题提供帮助。

FirstLetterToUpper 为C#函数,主要是把数据库表名的第一个字母变为大写(纯C#代码)。 SchemaExplorer 为CodeSmith提供的数据库访问库,可以用来获取数据库Schema的信息,如包含的表名,字段属性,主键外键等(后面具体介绍)
在主模板中,通过ActiveRecord 来访问子模板(名字ActiveRecord为注册子模板时定义) ,使用this.create创建子模板实例,然后传入TableName属性,调用RenderToFile 将子模板的结果写道指定的文件中。

此时在CodeSmith.csp 中添加主模板,配置数据库为Chinook,然后生成代码

Rendering output 'YiiDataModel'...

  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Album.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Artist.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Customer.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Employee.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Genre.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Invoice.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Invoiceline.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Mediatype.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Playlist.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Playlisttrack.php
  Generated: D:\tmp\ActiveRecordDemo\ActiveRecordDemo\protected\models\Track.php
  Generated: D:\tmp\ActiveRecordDemo\CodeSmith\YiiDataModel.txt
Done rendering outputs: 1 succeeded, 0 failed, 0 skipped (1111ms).


相关评论