Home Backend Development PHP Tutorial WEB编程架构革新初探

WEB编程架构革新初探

Jun 13, 2016 pm 12:15 PM
data id name nbsp post

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 />
Copy after login


\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 />
Copy after login


我把这些通用接口都写在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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Fix event ID 55, 50, 98, 140 disk error in event viewer Fix event ID 55, 50, 98, 140 disk error in event viewer Mar 19, 2024 am 09:43 AM

If you find event ID 55, 50, 140 or 98 in the Event Viewer of Windows 11/10, or encounter an error that the disk file system structure is damaged and cannot be used, please follow the guide below to resolve the issue. What does Event 55, File system structure on disk corrupted and unusable mean? At session 55, the file system structure on the Ntfs disk is corrupted and unusable. Please run the chkMSK utility on the volume. When NTFS is unable to write data to the transaction log, an error with event ID 55 is triggered, which will cause NTFS to fail to complete the operation unable to write the transaction data. This error usually occurs when the file system is corrupted, possibly due to the presence of bad sectors on the disk or the file system's inadequacy of the disk subsystem.

This Apple ID is not yet in use in the iTunes Store: Fix This Apple ID is not yet in use in the iTunes Store: Fix Jun 10, 2024 pm 05:42 PM

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

See all articles