|
| 1 | +--- |
| 2 | +title: CakePHP 5 Documentation - Build Better Web Applications Faster |
| 3 | +description: Official CakePHP 5 documentation. Learn how to build modern PHP web applications with convention over configuration, powerful ORM, built-in security, and rapid development tools. |
| 4 | +outline: 2 |
| 5 | +--- |
1 | 6 | # Build Better Web Applications, Faster |
2 | 7 |
|
3 | 8 | **CakePHP 5** is a modern PHP framework running on PHP |phpversion| (min. PHP |minphpversion|) that helps you write clean, maintainable code without the complexity. Whether you're building a simple blog or a complex enterprise application, CakePHP gives you the tools to get it done right. |
4 | 9 |
|
5 | 10 | ::: tip Perfect for |
6 | | -✅ Developers who value **convention over configuration** |
7 | | -✅ Teams building **secure, scalable applications** |
8 | | -✅ Projects that need to **ship quickly** without sacrificing quality |
| 11 | +✅ Developers who value **convention over configuration**<br> |
| 12 | +✅ Teams building **secure, scalable applications**<br> |
| 13 | +✅ Projects that need to **ship quickly** without sacrificing quality<br> |
9 | 14 | ✅ Applications requiring **modern PHP standards** (PSR-7, PSR-15, PSR-17) |
10 | 15 | ::: |
11 | 16 |
|
12 | 17 | ## Why CakePHP? |
13 | 18 |
|
14 | 19 | <div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin: 2rem 0;"> |
15 | 20 |
|
16 | | -🚀 **Rapid Development** |
| 21 | +🚀 **Rapid Development** |
17 | 22 | Scaffold applications in minutes with powerful code generation tools. |
18 | 23 |
|
19 | | -🔒 **Security First** |
| 24 | +🔒 **Security First** |
20 | 25 | Built-in protection against SQL injection, XSS, CSRF, and more. |
21 | 26 |
|
22 | | -📦 **Batteries Included** |
| 27 | +📦 **Batteries Included** |
23 | 28 | ORM, validation, caching, authentication — everything you need out of the box. |
24 | 29 |
|
25 | | -🎯 **Convention over Configuration** |
| 30 | +🎯 **Convention over Configuration** |
26 | 31 | Sensible defaults mean less setup, more coding. |
27 | 32 |
|
28 | 33 | </div> |
@@ -117,7 +122,7 @@ return [ |
117 | 122 | Choose your preferred approach for creating the database schema: |
118 | 123 |
|
119 | 124 | > [!NOTE] |
120 | | -> **Migrations** are recommended for team projects and production - they're version-controlled and database-agnostic. |
| 125 | +> **Migrations** are recommended for team projects and production - they're version-controlled and database-agnostic. |
121 | 126 | > **Raw SQL** is fine for quick prototyping or if you prefer direct database control. |
122 | 127 |
|
123 | 128 | #### Option A: Using Migrations |
@@ -289,11 +294,11 @@ class ArticlesTable extends Table |
289 | 294 | public function initialize(array $config): void |
290 | 295 | { |
291 | 296 | parent::initialize($config); |
292 | | - |
| 297 | + |
293 | 298 | $this->setTable('articles'); |
294 | 299 | $this->setDisplayField('title'); |
295 | 300 | $this->setPrimaryKey('id'); |
296 | | - |
| 301 | + |
297 | 302 | $this->addBehavior('Timestamp'); |
298 | 303 | } |
299 | 304 | } |
@@ -343,37 +348,37 @@ class ArticlesController extends AppController |
343 | 348 | $articles = $this->Articles->find('all') |
344 | 349 | ->where(['published' => true]) |
345 | 350 | ->orderBy(['created' => 'DESC']); |
346 | | - |
| 351 | + |
347 | 352 | $this->set(compact('articles')); |
348 | 353 | } |
349 | | - |
| 354 | + |
350 | 355 | public function view(?string $slug = null): void |
351 | 356 | { |
352 | 357 | $article = $this->Articles |
353 | 358 | ->findBySlug($slug) |
354 | 359 | ->firstOrFail(); |
355 | | - |
| 360 | + |
356 | 361 | $this->set(compact('article')); |
357 | 362 | } |
358 | | - |
| 363 | + |
359 | 364 | public function add(): void |
360 | 365 | { |
361 | 366 | $article = $this->Articles->newEmptyEntity(); |
362 | | - |
| 367 | + |
363 | 368 | if ($this->request->is('post')) { |
364 | 369 | $article = $this->Articles->patchEntity( |
365 | 370 | $article, |
366 | 371 | $this->request->getData() |
367 | 372 | ); |
368 | | - |
| 373 | + |
369 | 374 | if ($this->Articles->save($article)) { |
370 | 375 | $this->Flash->success('Article saved!'); |
371 | 376 | return $this->redirect(['action' => 'index']); |
372 | 377 | } |
373 | | - |
| 378 | + |
374 | 379 | $this->Flash->error('Unable to save article.'); |
375 | 380 | } |
376 | | - |
| 381 | + |
377 | 382 | $this->set(compact('article')); |
378 | 383 | } |
379 | 384 | } |
@@ -640,4 +645,4 @@ bin/cake bake all Articles |
640 | 645 | <a href="tutorials-and-examples" style="color: white; text-decoration: none; font-weight: 500; border-bottom: 1px solid rgba(255,255,255,0.5); padding-bottom: 2px;">View Examples</a> |
641 | 646 | </p> |
642 | 647 |
|
643 | | -</div> |
| 648 | +</div> |
0 commit comments