国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊 初品cakephp 入門基礎

初品cakephp 入門基礎

Jun 13, 2016 pm 12:02 PM
cakephp getting Started picture Base implement process Baidu Encyclopedia of


首先來看一下cakephp的的執(zhí)行流程(從百度百科借來的圖片):
1:首先你的服務器必須支持rewrite,如果是不支持rewrite的虛擬主機的話cakephp是不能正常運行的。
2:將所有的請求定向到cakephp框架后就進入了框架的route,cakephp帶有一套默認的分發(fā)規(guī)則(例如:http://……/test/test,在不做任何route配置的情況下cakephp會自動執(zhí)行test_controller控制器中的test方法)。
我們可以通過配置route的方式將任何請求指向我們所希望執(zhí)行的控制器和方法,配置如下(app/config/routes.php):

復制代碼 代碼如下:


Router::connect('/pages/*', array('controller' => 'test', 'action' => 'index'));


3:請求進入controller后cakephp會根據(jù)controller的名字去加載默認的model。例如:TestController會自動加載models下的test.php文件,接著我們就可以通過如下方法調(diào)用該model的方法了。

復制代碼 代碼如下:


$this->test->find('all');


查看cakephp框架的controller基類源碼(cake\libs\controller\controller.php的__mergeVars方法中)

復制代碼 代碼如下:


if ($this->uses !== null && $this->uses !== false) {
$merge[] = 'uses';
}
foreach ($merge as $var) {
if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
if ($var !== 'uses') {
$normal = Set::normalize($this->{$var});
$app = Set::normalize($appVars[$var]);
if ($app !== $normal) {
$this->{$var} = Set::merge($app, $normal);
}
} else {
$this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
}
}
}


在cakephp構造controller的時候將uses數(shù)組中的model會全部實例化。
4、5、6:是controller和model直接處理業(yè)務邏輯的一個過程,值得注意的是cakephp的model繼承自AppModel,在AppModel中已經(jīng)實現(xiàn)了一些數(shù)據(jù)庫的操作方法,并且model會默認關聯(lián)到數(shù)據(jù)庫中的表。這一點感覺不是很好,model只是一個數(shù)據(jù)庫的操作層了。
7:在進行完業(yè)務處理后,最終要數(shù)據(jù)要整合html輸出到瀏覽器端。在cakephp的視圖中包含布局文件、元素文件和模板文件,這些文件的在1.3版本中采用ctp的后綴,在controller基類里面可以修改var $ext = '.ctp';來改變模板文件的后綴。
小結:cakephp框架使用起來感覺不夠靈活,model層存在局限性。而視圖文件中采用的是php的語法不便于團隊開發(fā)中的任務分離。在小項目中cakephp還是游刃有余的,框架提供的腳手架、核心組件和一些類可以快速方便的構建一個項目。cakephp初識,認識可能存在偏差。
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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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)

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

ai tool recommendation ai tool recommendation Nov 29, 2024 am 11:08 AM

This article introduces six popular AI tools, including Douyin Doubao, Wenxin Yige, Tencent Zhiying, Baidu Feipiao EasyDL, Baidu AI Studio and iFlytek Spark Cognitive Large Model. These tools cover different functions such as text creation, image generation, video editing, and AI model development. Choosing the right AI tool requires consideration of factors such as functional requirements, technical level, and cost budget. These tools provide convenient and efficient solutions for individuals and businesses in need of AI assistance.

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

Another national product from Baidu is connected to DeepSeek. Is it open or follow the trend? Another national product from Baidu is connected to DeepSeek. Is it open or follow the trend? Mar 12, 2025 pm 01:48 PM

DeepSeek-R1 empowers Baidu Library and Netdisk: The perfect integration of deep thinking and action has quickly integrated into many platforms in just one month. With its bold strategic layout, Baidu integrates DeepSeek as a third-party model partner and integrates it into its ecosystem, which marks a major progress in its "big model search" ecological strategy. Baidu Search and Wenxin Intelligent Intelligent Platform are the first to connect to the deep search functions of DeepSeek and Wenxin big models, providing users with a free AI search experience. At the same time, the classic slogan of "You will know when you go to Baidu", and the new version of Baidu APP also integrates the capabilities of Wenxin's big model and DeepSeek, launching "AI search" and "wide network information refinement"

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

What are the AI ??tools? What are the AI ??tools? Nov 29, 2024 am 11:11 AM

AI tools include: Doubao, ChatGPT, Gemini, BlenderBot, etc.

Why can custom style sheets take effect on local web pages in Safari but not on Baidu pages? Why can custom style sheets take effect on local web pages in Safari but not on Baidu pages? Apr 05, 2025 pm 05:15 PM

Discussion on using custom stylesheets in Safari Today we will discuss a custom stylesheet application problem for Safari browser. Front-end novice...

See all articles