开发者

possible to make codeigniter work with another framework?

the situation is this.

my client (who also is a programmer) asks me to develop an address book (with mysql database) with a lot of functions. then he can interact with some class methods i provide for him. kinda like an API.

the situation is that the address book application is getting bigger and bigger, and i feel like its way better to use CodeIgniter to code it with MVC.

i wonder if i can use codeigniter, then in some way give him the access to controller methods.

eg. in a controller there are some functions u can call with the web browser.

public function create_contact($information) {..}

public function delete_contact($id) {..}

public function get_contact($id) {..}

however, these are just callable from web browser. how can i let my client have access to these functions like an API?

then in his own application he can use:

$result = $address_book->create_contact($information);
if($result) {
    echo "Success";
}

$contact = $address_book->get_contact($id);

in this way, my controller methods are handling the in and out with the Models. there will be no views, cause i just have to return the data/result from the Models. and he c开发者_JAVA技巧an just use my "API" functions.

is this possible?

cause i just know how to access the controller methods with the webbrowser. and i guess its not an option for him to use header(location) to access them.

all suggestions to make this possible are welcomed! even other approaches to let me use CI to develop. perhaps there already are best practices regarding this kind of cross framework collaboration?

thanks


MVC seems to have dispersed in its definition. This definition I will offer should be ideal for you.

Models are where you build your business end of the application. Operations such as create_contact, delete_contact, and get_contact belong in the model layer. The model layer is what builds your application API and should be entirely independent.

Consider the controllers purely as the user's puppeteers. Controllers accept user input - the validation, sanitation, and whatnot may be done elsewhere - and invokes the API you've already setup in the model layer. Also, controllers then specify what view to use - however complicated or simple your presentation layer is.

The presentation layer usually isn't the difficulty. As long as you are only using read operations in the view you should be fine.

To clarify, if a user wants to create a new contact, the controller may need a method called create_contact that accepts the appropriate input. However, the actual operation of creating the contact must be done in the model layer. This will allow your other developer to reuse that same operation in a completely different application by loading your model, which was already designed as an independent entity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜