English 中文(简体)
What do you have in your Model class?
原标题:
  • 时间:2009-12-03 21:33:13
  •  标签:
  • php
  • model

What do you have in your model classes. Generally if i use any framework or any library (Zend Framework) , my classes only have variable which is table name . I know that in complicated applications models have lots of thing to do , so i want to know what these jobs are.

Maybe instead of using library`s general select function ,you create special functions to get data from database ( getUserById() ) . To sum up , which parts of the process should go in to model layer.

For example thing about general user processes .So in registration process where should we check email is acceptable or not . This is example just explain what do you do in your model layer.

This question may seem as an abstract question because of my english , but it is not . If you can edit it please improve it . The purpose of this question is better understanding of mvc pattern

问题回答

Well, in general, models should do the main work regarding your business layer. So, if you have a pretty complex query using (and combining) the accessor functions of the database layer (thus, your model), you should instead write an extra function for that query in your model class. Makes it much easier to change the implementation of your model (e.g. database-table-wise).

EDIT: To answer your other question: validating an e-mail should happen in the controller, usually using some kind of component, utility class or library...





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签