search
HomeBackend DevelopmentPHP TutorialWEB编程架构革新初探

WEB编程架构改革初探

长久以来,编程MVC架构深入人心。随着编程语言的不断进步和发展。这种架构始终没有进步, 我们尝试着将MVC模式大胆进化为VC模式。【千万注意】,我用的是进化,是先有MVC,再有VC。而不是直接VC模式。

再次强调,不是说MVC模式不好。其实还可以进化得更好。当MVC模式你还不熟悉的时候,你无法理解VC模式。
表面上省略掉Model,是编程语言进化的结果。而不是退步。为此会带来效率的大幅度提升。。。

一、 省略掉model的前提条件。
二、 省略掉model的实现。
三、 省略掉model后的强大好处。
四、 如何弥补省略掉model所失去的功能?
五、 为此VC架构的php框架实现。
以上功能下面慢慢补充…
在此抛砖引玉,希望大家不吝赐教。。。。
跟贴有分啊。。。。

------解决思路----------------------

引用:
Quote: 引用:

先丢块砖:你这是退化到 MV


【千万注意】,我用的是进化,是先有MVC,再有VC。而不是直接VC模式。
'
只是说了总纲,具体怎么做呢?
------解决思路----------------------
还有这样进化的哇,占个座看楼主继续发表观点。
------解决思路----------------------
MVC中M的主要是处理数据库或者业务逻辑。
更简单的说,其实把C看成商人,V看成顾客,而M则看成生产商。当生产商(M)取消后,那么意味着商人(C)就要承担生产商(M)的责任。虽然看似省略了一步,但其实只是内部消化而已,没了M,那么必然会有另一种产物来替代,来解决所有只在C中处理的业务。当然,也可以都用C,不用M或另一种替代M的方案,这也会使C的负担增大,代码也会更加复杂,代码重用性也会相对降低等等。Thinkphp中封装的一些数据库操作的方法,但未必就不是M的代替口。

个人观点,不喜勿喷~~~
------解决思路----------------------
楼主只考虑数据库,如果是非数据库的业务逻辑操作,这个MODEL要放在那里?
------解决思路----------------------
既然楼主已经有这样的一个框架,那就共享出来大家学习一下吧。
------解决思路----------------------
这个就是写在C里的M吧,我最初碰到前台会员和后台管理员都需要编辑产品的时候也是这样做的(ThinkPHP)

\Admin\Controller\ProductController.class.php:

<br />namespace Admin\Controller;<br />use Api\Controller\ProductController as ApiProduct;<br />class ProductController extends AdminController {<br />    public function edit() {<br />        if (I('submit')) {<br />            $res = ApiProduct::setInfo(I());<br />            if ($res === true) {<br />                $alert = I('id') ? '编辑成功' : '发布成功';<br />                $this->success($alert, '/admin/product');<br />                exit;<br />            } else {<br />                $this->error($res);<br />            }<br />        }<br /><br />        I('id') && $this->data = ApiProduct::getInfo(I('id'));<br />        $this->cate = ApiProduct::getCate();<br />        $this->paramdata = ApiProduct::getParam();<br />        $this->param = C('YH_PARAM');<br />        $this->title = I('id') ? '商品编辑' : '商品发布';<br />        $this->display('product/edit');<br />    }<br />}<br />


\Api\Controller\ProductController.class.php:

<br />    public function getInfo($id) {<br />        $id = intval($id);<br />        $data = M('product')->where("id = $id")->find();<br />        $stripfield = array('name', 'name_en', 'content', 'content_en');<br />        foreach ($stripfield as $field) {<br />            $data[$field] = stripslashes($data[$field]);<br />        }<br />        $data['adddate'] = date('Y-m-d', $data['addtime']);<br />        $data['pathArr'] = explode('-', $data['path']);<br />        $data['img'] = ImageController::getAll(1, $id);<br />        return $data;<br />    }<br /><br />    public function setInfo($post) {<br />        $id = intval($post['id']);<br />        $data = array();<br />        $data['logo'] = $post['logo'];<br />        $data['name'] = $post['name'];<br />        $data['name_en'] = $post['name_en'];<br />        $cid = intval($post['cid']);<br />        $data['path'] = self::getCatePath($cid);<br />        list($top) = explode('-', $data['path']);<br />        $param = C('YH_PARAM');<br />        foreach ($param as $key => $val) {<br />            $data[$val['field']] = $post[$val['field']][$top];<br />        }<br />        $data['content'] = $post['content'];<br />        $data['content_en'] = $post['content_en'];<br />        $data['urltb'] = format_url($post['urltb']);<br />        $data['urlone'] = format_url($post['urlone']);<br />        $data['urljd'] = format_url($post['urljd']);<br /><br />        if (empty($data['name']) <br><font color='#FF8000'>------解决思路----------------------</font><br> empty($data['name_en'])) {<br />            return '商品名称不能为空';<br />        }<br />        if (empty($data['path'])) {<br />            return '请选择分类';<br />        }<br /><br />        if ($id) {<br />            $data['id'] = $id;<br />            M('product')->save($data);<br />        } else {<br />            $data['addtime'] = time();<br />            $id = M('product')->add($data);<br />        }<br /><br />        ImageController::addImg($post['newimg'], 1, $id);<br />        ImageController::delImg($post['delimg']);<br />        if (empty($data['logo'])) {<br />            $logo = ImageController::getOne(1, $id);<br />            M('product')->where("id = $id")->setField('logo', $logo);<br />        }<br /><br />        return true;<br />    }<br /><br />


我把这些通用接口都写在C里面了,但觉得实际上就是M...
比如登陆操作,有个login接口,若干个参数。传入用户名密码然后返回true或是失败原因。这个过程中要写session或是向session服务器提交。是否需要记住密码自动登陆?这个参数会影响到写cookie。是否把登陆id记录到共享内存中实现一些其他功能?我觉得这些操作都算在用户登陆的M里
------解决思路----------------------
那你干脆打混战,还讨论什么架构干什么?
快 70 了精力有限,偶尔接个小项目做做。泡论坛是为了不落伍,不动动脑筋不就痴呆了?
------解决思路----------------------

Laravel的作者写了一本书叫《From Apprentice To Artisan》,里面有个章节叫。好像楼主已经到了跟大神同样的境界了。楼主可以去看看这本书。。。

具体没看懂,作者开发的框架里面有非常明确的MVC文件夹。但是写的书却推翻的了这个观点。楼主有兴趣研究那个吧。thinkphp已经不属于你研究的范畴了。


------解决思路----------------------
框架没有完全的好坏之分,只有适合不适合而已。。
楼主的这个小改革,是没有遇到复杂的业务吧。。
我们这边是在M和C之间增加了module,C只是串联各个module而已,module操作model来实现。。对于各个业务模块的耦合度很低,感觉确实很好用。。
------解决思路----------------------
I learnt a word today: Narcissism
------解决思路----------------------
引用:
Quote: 引用:

I learnt a word today: Narcissism

I also learnt a word today: wuzhi&&youzhi.


P.S., ur pinyin and English mashup is so cool! Wait a second, did you just copy & paste what I wrote and then appended your pinyin? That's not cool. That sucks for a former fortune 500 PM!!!
------解决思路----------------------
                $data['company_id']=$_POST['id'];
                $data['kefu_name']=$_POST['kefu_name'];
                $data['passwd']=$_POST['passwd'];
                $data['kefu_type']=$_POST['kefu_type'];
                $data['kefu_name']=$_POST['kefu_name'];
                $data['open_time']=time();

这种已经很复杂了啊, 也许你要说这都是代码生成器生成的, 但是修改数据库表结构的造成的改动呢, 还是得一个字段一个字段的写, 这只是一个缩引, HTML展示页面也要一个一个写么?
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software