如何在Controller生成模型文件

各位前辈,我在开发一个CMS,在开发系统模型遇到了个难题,比如我在后台新建一个产品模型,自动生成了相应的数据表,但是怎么去生成这个表的model文件呢?总不能发布后也让人家用GII生成吧,所以我想在Controller中能不能实现,该怎么做?先谢过了!

看这

  1. I am not quite familiar with Yii, but good at CMS.

For such issue, my solution is:

  1. Gii call frameworks/.../templates to generate model files, so why not you generate in your function instead of in ‘Gii’?

(2.a) write a server-side script by using perl, bash, or php, to do the copy stuff, like:

cp yii/frameworks/templates/… webroot/protected/…

(2.B) as well as the variables replace, such as classname, etc. e.g.:

sed -e ‘s/original_classname/myweb_clasname/’ files …

(2.c) name this script -> processing.sh

(2.d) in your front-side to call this script, something should like:

function generate_module(params) {

system(‘process.sh &’);

}

(2.e) make sure the permission issues.

(3) it works for me. I think this is the only way you have to do to call Yii APIs by using server-side scripts in your PHP codes when user trigger the event.