开发者

CakePHP. Where to put scripts that populate database?

I am working on a CakePHP project that has a database populated from multiple text files. I didn't write most of the scripts that populate database (they are written in Perl/Python). There are a couple PHP scripts though that I created that alter some data in a database according to information in some additional text files. My question is where all of these scripts fit the best in CakePHP application. What would be the common practice that would allow user to use my PHP script to mod开发者_开发知识库ify info in database again if necessary?


would allow user to use my PHP script to modify info in database again if necessary?

Since you're dealing with the database the obvious choice here would be to create a model that approved users can utilize to alter your database.

Here's a very simple example of what I might do:

class Alter extends AppModel {

    // tells the model not to use a database table
    public $useTable = false;

    public function do_stuff() {
        // your code to include scripts and alter database with, I'm assuming, raw SQL
    }

}

Then you'd need a controller for that model

class AltersController extends AppController {

    public function edit($param1, $param2) {
         // code here to access the model
         $this->Alter->do_stuff();
    }

}

Now your users can edit the database as needed. Your data logic also is properly encapsulated in the model, where I believe it should go.

Edit:

In regards to OP's question. Here's an article that talks about using Perl with PHP.


As cakePHP is MVC you should place all the scripts that your talking about in the controllers. So lets say you table is called: "posts" All the CRUD functions should be in the model - all access to the models should be from the controllers. Basically, the logic that talks to the DB should be in the Model, the functions that call that logic should be in the Controllers. I hope this better explains what I meant before I edited the answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜