search
HomeBackend DevelopmentPHP Tutorial 请教在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>
探讨

我现在维护的网站是phpcms 的架构有点不太清楚,多谢个位指点。

------解决方案--------------------
多看看框架的源码,不同的框架是不同的
------解决方案--------------------
mvc中的M是Model,也就是程序功能和程序的构成方式比如数据库,V就是View图形界面,C就是Controller转发请求、处理请求。放在B/S模式里V就是浏览器呈现的东西,C就是服务器的php程序。

回到楼主的“在v层中应该怎样调取c中的方法”的问题,那就简单了,那就是使用post、get或者ajax了。
------解决方案--------------------
上面的ajax其实也就是post、get

其实也有其他方法,只要是浏览器给服务器发送参数,服务器根据发送的参数进行相应的动作就是了。
------解决方案--------------------
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
How does PHP identify a user's session?How does PHP identify a user's session?May 01, 2025 am 12:23 AM

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

What are some best practices for securing PHP sessions?What are some best practices for securing PHP sessions?May 01, 2025 am 12:22 AM

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

Where are PHP session files stored by default?Where are PHP session files stored by default?May 01, 2025 am 12:15 AM

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

How do you retrieve data from a PHP session?How do you retrieve data from a PHP session?May 01, 2025 am 12:11 AM

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

How can you use sessions to implement a shopping cart?How can you use sessions to implement a shopping cart?May 01, 2025 am 12:10 AM

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

How do you create and use an interface in PHP?How do you create and use an interface in PHP?Apr 30, 2025 pm 03:40 PM

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

What is the difference between crypt() and password_hash()?What is the difference between crypt() and password_hash()?Apr 30, 2025 pm 03:39 PM

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

How can you prevent Cross-Site Scripting (XSS) in PHP?How can you prevent Cross-Site Scripting (XSS) in PHP?Apr 30, 2025 pm 03:38 PM

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

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

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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