【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
MVC的是解决 人机交互 的一种设计模式, 核心的理念将 界面展示(View) 和业务处理(Model)剥离开,通过一个控制器(Controller)来控制 界面和业务处理之间联系。
通过MVC,可以让程序获得极大的灵活性、可维护性和可重用性。
大部分应用涉及到人机交互,都离不开MVC。理解这个应该不难~~
MVC是水平划分? 那垂直划分是什么思路?
一般的流程就是,连接数据库,查询数据库,循环输出html结果。
<?php mysql_connect(…); $result = mysql_query('select * from news order by article_date desc'); ?> <html> <body> <h1>News Articles</h1> <?php while ($row = mysql_fetch_object($result)) { ?> <h2><?php echo $row->headline ?></h2> <p> <?php echo $row->body ?> </p> <?php } ?> </body> </html>
采用MVC方式则如下。
model:
<?php function get_articles() { mysql_connect(…); $result = mysql_query('select * from news order by article_date desc'); $articles = array(); while ($row = mysql_fetch_objects($result)) { $articles[] = $row; } return $articles; } ?>
controller:
<?php $articles = get_articles(); display_template('articles.tpl'); ?>
view:
<html> <body> <h1>News Articles</h1> <?php foreach ($articles as $row) { ?> <h2><?php echo $row->headline ?></h2> <p> <?php echo $row->body ?> </p> <?php } ?> </body> </html>
原文:http://www.nowamagic.net/php/php_ShowSimpleMvc.php
垂直划分就是按照软件的功能模块划分,例如XX管理一块、XX统计一块,然后每个模块落实到人头上,随他用MVC还是CVM还是什么模式开发。
你讲的水平划分最大的缺点就是如果Model层有变化,会导致View的大改动,如果多人开发,有得扯皮呢
nice
一直对M和C不是很理解,经常混用,这回算是理解透了!
功能划分是正确的, 就是 By Use Case
我只用 C V: 一个C 代表一个Use Case.
C:
public function action_index(){ $_page = new UTL('user/index'); $_sql = 'select * from v_user where '.Cms_DB::getCURTreeSql($this->user, true,'role_id','id'); if(isset($_GET['name'])){ $_filter = DB::quote($_GET['name'].'%'); $_sql .= ' and username like '.$_filter; $_page->name = $_GET['name']; } Cms_DB::getPage($_sql,$_page,'id desc','users'); return $this->content($_page); }
{if:users} <div class="bPageBlock"> <table> <thead> <tr class="headerRow"><th>User Name</th><th>Profile</th><th>Role</th><th>Language</th><th>Cms Auth</th><th>Action</th></tr> </thead> <tbody> {foreach:users,$user} <tr class="dataRow"><td>{$user.username}</td> <td><a href="{base_url}user/profile/{$user.profile_id}">{$user.profile_name}</a></td> <td><a href="{base_url}user/role/{$user.role_id}">{$user.role_name}</a></td> <td>{$user.language}</td> <td >{if:$user.activated==DB::T}<a class="ajax-linkreload" href="{base_url}user/deactivate/{$user.id}">Deactivate</a>{else} <a class="ajax-linkreload" href="{base_url}user/activate/{$user.id}">Activate</a>{end}</td> <td><a class="ajax-linkwarn" href="{base_url}user/resp/{$user.id}">Reset User Password</a> <a href="{base_url}user/set/{$user.id}">Edit</a></td> </tr> {end} </tbody> </table> {end} <div> {if:isset(pagination)} {pagination} {end} </div>
引用来自“mallon”的答案
MVC的是解决 人机交互 的一种设计模式, 核心的理念将 界面展示(View) 和业务处理(Model)剥离开,通过一个控制器(Controller)来控制 界面和业务处理之间联系。
通过MVC,可以让程序获得极大的灵活性、可维护性和可重用性。
大部分应用涉及到人机交互,都离不开MVC。理解这个应该不难~~
MVC是水平划分? 那垂直划分是什么思路?
一般的流程就是,连接数据库,查询数据库,循环输出html结果。
采用MVC方式则如下。
model:
controller:
view:
原文:http://www.nowamagic.net/php/php_ShowSimpleMvc.php
引用来自“Binny”的答案
引用来自“mallon”的答案
MVC的是解决 人机交互 的一种设计模式, 核心的理念将 界面展示(View) 和业务处理(Model)剥离开,通过一个控制器(Controller)来控制 界面和业务处理之间联系。
通过MVC,可以让程序获得极大的灵活性、可维护性和可重用性。
大部分应用涉及到人机交互,都离不开MVC。理解这个应该不难~~
MVC是水平划分? 那垂直划分是什么思路?
垂直划分就是按照软件的功能模块划分,例如XX管理一块、XX统计一块,然后每个模块落实到人头上,随他用MVC还是CVM还是什么模式开发。
你讲的水平划分最大的缺点就是如果Model层有变化,会导致View的大改动,如果多人开发,有得扯皮呢
引用来自“摇滚21”的答案
一般的流程就是,连接数据库,查询数据库,循环输出html结果。
采用MVC方式则如下。
model:
controller:
view:
原文:http://www.nowamagic.net/php/php_ShowSimpleMvc.php
nice
引用来自“摇滚21”的答案
一般的流程就是,连接数据库,查询数据库,循环输出html结果。
采用MVC方式则如下。
model:
controller:
view:
原文:http://www.nowamagic.net/php/php_ShowSimpleMvc.php
一直对M和C不是很理解,经常混用,这回算是理解透了!
引用来自“Mallon”的答案
功能划分是正确的, 就是 By Use Case
我只用 C V: 一个C 代表一个Use Case.
C: