3

我是 cakephp 新手。我想知道 php 代码如何执行扩展名为 .ctp 的文件。php如何在cakephp中的.ctp文件扩展名中执行?如何使用 cakephp 技术在扩展名为 .css 的文件中执行 php 代码?

4

3 回答 3

2

视图中的代码被执行是因为 Cake 使用include它来处理它。你可以自己做同样的事情:

include('any_file_you_want.with_any_extension');

只要有一个 PHP 开始标签并且语法正确,该文件中的任何代码都将被执行。

于 2013-03-01T11:01:00.077 回答
1

看 cakephp 遵循 MVC 架构。

Hence the files structures are divided into 3 main modules:-

1.Model:- This the file in which you write your validations.
2.COntroller:- This the file where you write your programs logic.
3.View:- This is the file where you write your output/design in the form of HTML and also write Java script.

Now coming back to your question. The .ctp files are nothing but the View part of the cakephp. They are initiated/ called by the controllers. The controllers act as a heart of ur php.They are the one's to call your .ctp file and execute the file and also css files are called and handled by them only.

Go through the documentation throughly...

我知道文档可能有点混乱,阅读 4 到 5 次你就会了解每件事...

于 2013-03-01T05:04:12.130 回答
0

CakePHP 是基于 MVC 结构的 PHP 框架。MVC 代表模型视图控制器。

模型:您的数据库表在其中定义以及所有处理和验证,例如如果您有名为“USER”的表,那么要访问该表,您将在模型目录中创建 UserModel.php。

控制器:对于每个模型,为我们的业务逻辑定义一个控制器。这里我们的控制器名称将是 UsersController.php

查看:: 查看文件的扩展名为 .ctp。它定义了数据将如何在客户的浏览器上显示。

CakePHP 的流程:客户端请求将转到第一个 UsersController.php。控制器将从 UserModel.php 中获取数据。在处理检索到的数据后,控制器将此数据传递给 View。View(.ctp) 文件包含 HTML、CSS 和客户端脚本数据,这些数据将返回到显示它的客户端计算机。

于 2013-03-01T10:55:08.157 回答