请教在php mvc 中 在v层中应该怎样调取c中的方法呢
请问在php mvc 中 在v层中应该怎样调取c中的方法呢?
请问在php mvc 中 在v层中应该怎样调取c中的方法呢?数据模型m和逻辑层都已经被项目经理建成,就是不清楚如何调用,
请问应该如何调用输出方法呢?请多指导,我是刚刚参加工作不久,对mvc 不了解,谢谢各位。
------解决方案--------------------
这个问题 类似
电视机(MVC)的显示屏(V)怎么调用换台(C)操作。
------解决方案--------------------
C层解析模板 进行替换V层的变量
或者C层直接 include V层,不就可以直接调用C层的遍了么?
------解决方案--------------------
建议你还是先看看MVC的基础比较好~这样的做法是不合理的
------解决方案--------------------
有空去看看框架,比如thinkphp,zendframwork。..还有开源产品joomla ,dedecms.....
------解决方案--------------------
那要看你们公司用的是什么框架了,不同的框架调用的方法不一样。
------解决方案--------------------
V一般是展示变量和数组,很少有把逻辑写在v里面,一般都在c或者m层就处理好了,然后在c层把数据赋值到视图v上。你这样做不合理。
------解决方案--------------------
写个公共函数 哪里调都可以!!
------解决方案--------------------
在PHP CodeIgniter中,是在C里直接调用V的,跟你说的正好相反。Controller调用Model和View。
------解决方案--------------------
有些框架有固定的写法,好象Zend有这样的:
- HTML code
<a href="<?php%20echo%20%24this->url(array(" action>"query","controller"=>"db"));?>" >try</a><br><font color="#e78608">------解决方案--------------------</font><br>像smarty那样 c向v注册变量 v用变量名访问<br><br><font color="#e78608">------解决方案--------------------</font><br>这种做法是不建议的,我不知道你们是怎样实现这个分层的,<br><br>我想楼主可以去先弄清MVC三层各层的职责,在V里面调用C里面的函数或者说方法,不是一个好的做法<br><font color="#e78608">------解决方案--------------------</font><br>路过的<br><font color="#e78608">------解决方案--------------------</font><br>路过的jbknknk<br><font color="#e78608">------解决方案--------------------</font><br>http://wenku.baidu.com/view/a5aede00bed5b9f3f90f1cb1.html<br>你可以参考一下这篇文章 自己做一个就会明白了<br><font color="#e78608">------解决方案--------------------</font><br>如果用的是MVC结构<br>其实V层就相当与在C层中一样<br>因为基本都是用include v层的<br>v层可以直接调用调用它的c中的方法<br><font color="#e78608">------解决方案--------------------</font><br>都学过没有呀??大多数怎么都瞎说那?<br><font color="#e78608">------解决方案--------------------</font><br>哎~~~~~~~~~~~~~~~~~~···<br><font color="#e78608">------解决方案--------------------</font><br>这个一般是不允许的,如果强行做,可以把 c对象本身传给v,这样就行。<br><br>$this->view->c = $this.<br><br>其他可以使用注册器,只要在注册器里注册的,都可调用。<br><br>一般, v层只显示变量。不调用其他. 公共函数也是一种方法!<br><br><br><br><font color="#e78608">------解决方案--------------------</font><br>
------解决方案--------------------
多看看框架的源码,不同的框架是不同的
------解决方案--------------------
mvc中的M是Model,也就是程序功能和程序的构成方式比如数据库,V就是View图形界面,C就是Controller转发请求、处理请求。放在B/S模式里V就是浏览器呈现的东西,C就是服务器的php程序。
回到楼主的“在v层中应该怎样调取c中的方法”的问题,那就简单了,那就是使用post、get或者ajax了。
------解决方案--------------------
上面的ajax其实也就是post、get
其实也有其他方法,只要是浏览器给服务器发送参数,服务器根据发送的参数进行相应的动作就是了。
------解决方案--------------------

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

When a SpringBoot novice creates a project, the Controller cannot be scanned for a series of problems 1.2.3.4.5.6. Another way is to add @ComponentScan(basePackages={"xxx.xxx.xx","xxx.xxx" when starting the service class) .xx”}) is the fully qualified name of the package, which can be used for multiple SpringBoot custom controllers. The SpringBoot custom controller route cannot be scanned and cannot be found because the startup class and the custom Controller package are not in the same directory. Officially recommended placement of application.java

Laravel is one of the most popular PHP frameworks currently, and its powerful view generation capabilities are impressive. A view is a page or visual element displayed to the user in a web application, which contains code such as HTML, CSS, and JavaScript. LaravelView allows developers to use a structured template language to build web pages and generate corresponding views through controllers and routing. In this article, we will explore how to generate views using LaravelView. 1. What

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Introduction In today's rapidly evolving digital world, it is crucial to build robust, flexible and maintainable WEB applications. The PHPmvc architecture provides an ideal solution to achieve this goal. MVC (Model-View-Controller) is a widely used design pattern that separates various aspects of an application into independent components. The foundation of MVC architecture The core principle of MVC architecture is separation of concerns: Model: encapsulates the data and business logic of the application. View: Responsible for presenting data and handling user interaction. Controller: Coordinates the interaction between models and views, manages user requests and business logic. PHPMVC Architecture The phpMVC architecture follows the traditional MVC pattern, but also introduces language-specific features. The following is PHPMVC

Preface In some cases, the prefixes in the service controller are consistent. For example, the prefix of all URLs is /context-path/api/v1, and a unified prefix needs to be added to some URLs. The conceivable solution is to modify the context-path of the service and add api/v1 to the context-path. Modifying the global prefix can solve the above problem, but there are disadvantages. If the URL has multiple prefixes, for example, some URLs require prefixes. If it is api/v2, it cannot be distinguished. If you do not want to add api/v1 to some static resources in the service, it cannot be distinguished. The following uses custom annotations to uniformly add certain URL prefixes. one,

The MVC architecture (Model-View-Controller) is one of the most popular patterns in PHP development because it provides a clear structure for organizing code and simplifying the development of WEB applications. While basic MVC principles are sufficient for most web applications, it has some limitations for applications that need to handle complex data or implement advanced functionality. Separating the model layer Separating the model layer is a common technique in advanced MVC architecture. It involves breaking down a model class into smaller subclasses, each focusing on a specific functionality. For example, for an e-commerce application, you might break down the main model class into an order model, a product model, and a customer model. This separation helps improve code maintainability and reusability. Use dependency injection

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:
