Skip to content

Commit 4e57d17

Browse files
committed
Photoblog example code
0 parents  commit 4e57d17

File tree

938 files changed

+218345
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

938 files changed

+218345
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/app/Config
2+
/app/tmp
3+
/lib/Cake/Console/Templates/skel/tmp/
4+
/plugins
5+
/vendors
6+
.DS_Store
7+
tags

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "app/Plugin/DebugKit"]
2+
path = app/Plugin/DebugKit
3+
url = [email protected]:cakephp/debug_kit.git

.htaccess

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine on
3+
RewriteRule ^$ app/webroot/ [L]
4+
RewriteRule (.*) app/webroot/$1 [L]
5+
</IfModule>

README

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Active Record, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility.
2+
3+
The Cake Software Foundation - promoting development related to CakePHP
4+
http://cakefoundation.org/
5+
6+
CakePHP - the rapid development PHP framework
7+
http://www.cakephp.org
8+
9+
Cookbook - user documentation for learning about CakePHP
10+
http://book.cakephp.org
11+
12+
API - quick reference to CakePHP
13+
http://api.cakephp.org
14+
15+
The Bakery - everything CakePHP
16+
http://bakery.cakephp.org
17+
18+
The Show - live and archived podcasts about CakePHP and more
19+
http://live.cakephp.org
20+
21+
CakePHP TV - screen casts from events and video tutorials
22+
http://tv.cakephp.org
23+
24+
CakePHP Google Group - community mailing list and forum
25+
http://groups.google.com/group/cake-php
26+
27+
#cakephp on irc.freenode.net - chat with CakePHP developers
28+
irc://irc.freenode.net/cakephp

app/.htaccess

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine on
3+
RewriteRule ^$ webroot/ [L]
4+
RewriteRule (.*) webroot/$1 [L]
5+
</IfModule>

app/Console/Command/Task/empty

Whitespace-only changes.

app/Console/Templates/empty

Whitespace-only changes.

app/Console/cake

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
################################################################################
3+
#
4+
# Bake is a shell script for running CakePHP bake script
5+
# PHP 5
6+
#
7+
# CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8+
# Copyright 2005-2011, Cake Software Foundation, Inc.
9+
#
10+
# Licensed under The MIT License
11+
# Redistributions of files must retain the above copyright notice.
12+
#
13+
# @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
14+
# @link http://cakephp.org CakePHP(tm) Project
15+
# @package app.Console
16+
# @since CakePHP(tm) v 2.0
17+
# @license MIT License (http://www.opensource.org/licenses/mit-license.php)
18+
#
19+
################################################################################
20+
LIB=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && LIB=$LIB/$(basename -- "$0")
21+
22+
while [ -h "$LIB" ]; do
23+
DIR=$(dirname -- "$LIB")
24+
SYM=$(readlink "$LIB")
25+
LIB=$(cd "$DIR" && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
26+
done
27+
28+
LIB=$(dirname -- "$LIB")/
29+
APP=`pwd`
30+
31+
exec php -q "$LIB"cake.php -working "$APP" "$@"
32+
33+
exit;

app/Console/cake.bat

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2+
::
3+
:: Bake is a shell script for running CakePHP bake script
4+
:: PHP 5
5+
::
6+
:: CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
7+
:: Copyright 2005-2011, Cake Software Foundation, Inc.
8+
::
9+
:: Licensed under The MIT License
10+
:: Redistributions of files must retain the above copyright notice.
11+
::
12+
:: @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
13+
:: @link http://cakephp.org CakePHP(tm) Project
14+
:: @package app.Console
15+
:: @since CakePHP(tm) v 2.0
16+
:: @license MIT License (http://www.opensource.org/licenses/mit-license.php)
17+
::
18+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
19+
20+
:: In order for this script to work as intended, the cake\console\ folder must be in your PATH
21+
22+
@echo.
23+
@echo off
24+
25+
SET app=%0
26+
SET lib=%~dp0
27+
28+
php -q "%lib%cake.php" -working "%CD% " %*
29+
30+
echo.
31+
32+
exit /B %ERRORLEVEL%

app/Console/cake.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/php -q
2+
<?php
3+
/**
4+
* Command-line code generation utility to automate programmer chores.
5+
*
6+
* PHP 5
7+
*
8+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
9+
* Copyright 2005-2011, Cake Software Foundation, Inc.
10+
*
11+
* Licensed under The MIT License
12+
* Redistributions of files must retain the above copyright notice.
13+
*
14+
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
15+
* @link http://cakephp.org CakePHP(tm) Project
16+
* @package app.Console
17+
* @since CakePHP(tm) v 2.0
18+
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
19+
*/
20+
$ds = DIRECTORY_SEPARATOR;
21+
$dispatcher = 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php';
22+
$found = false;
23+
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
24+
25+
foreach ($paths as $path) {
26+
if (file_exists($path . $ds . $dispatcher)) {
27+
$found = $path;
28+
}
29+
}
30+
31+
if (!$found && function_exists('ini_set')) {
32+
$root = dirname(dirname(dirname(__FILE__)));
33+
ini_set('include_path', $root . $ds. 'lib' . PATH_SEPARATOR . ini_get('include_path'));
34+
}
35+
36+
if (!include($dispatcher)) {
37+
trigger_error('Could not locate CakePHP core files.', E_USER_ERROR);
38+
}
39+
unset($paths, $path, $found, $dispatcher, $root, $ds);
40+
41+
return ShellDispatcher::run($argv);

app/Controller/AppController.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
class AppController extends Controller {
4+
5+
public $helpers = array(
6+
'Paginator' => array('className' => 'BootstrapPaginator'),
7+
'Form' => array('className' => 'BootstrapForm'),
8+
'Session',
9+
'Html',
10+
'Text',
11+
//'Cache'
12+
);
13+
14+
public $components = array(
15+
'Security' => array('csrfUseOnce' => true),
16+
'RequestHandler',
17+
'Session',
18+
'Auth',
19+
'DebugKit.Toolbar'
20+
);
21+
22+
//public $cacheAction = '+10 seconds';
23+
}

app/Controller/Component/empty

Whitespace-only changes.

app/Controller/LabelsController.php

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
App::uses('AppController', 'Controller');
3+
/**
4+
* Labels Controller
5+
*
6+
* @property Label $Label
7+
*/
8+
class LabelsController extends AppController {
9+
10+
11+
/**
12+
* index method
13+
*
14+
* @return void
15+
*/
16+
public function index() {
17+
$this->Label->recursive = 0;
18+
$this->set('labels', $this->paginate());
19+
}
20+
21+
/**
22+
* view method
23+
*
24+
* @param string $id
25+
* @return void
26+
*/
27+
public function view($id = null) {
28+
$this->Label->id = $id;
29+
if (!$this->Label->exists()) {
30+
throw new NotFoundException(__('Invalid label'));
31+
}
32+
$this->set('label', $this->Label->read(null, $id));
33+
}
34+
35+
/**
36+
* add method
37+
*
38+
* @return void
39+
*/
40+
public function add() {
41+
if ($this->request->is('post')) {
42+
$this->Label->create();
43+
if ($this->Label->save($this->request->data)) {
44+
$this->Session->setFlash(__('The label has been saved'), 'success');
45+
$this->redirect(array('action' => 'index'));
46+
} else {
47+
$this->Session->setFlash(__('The label could not be saved. Please, try again.'), 'error');
48+
}
49+
}
50+
$photos = $this->Label->Photo->find('list');
51+
$this->set(compact('photos'));
52+
}
53+
54+
/**
55+
* edit method
56+
*
57+
* @param string $id
58+
* @return void
59+
*/
60+
public function edit($id = null) {
61+
$this->Label->id = $id;
62+
if (!$this->Label->exists()) {
63+
throw new NotFoundException(__('Invalid label'));
64+
}
65+
if ($this->request->is('post') || $this->request->is('put')) {
66+
if ($this->Label->save($this->request->data)) {
67+
$this->Session->setFlash(__('The label has been saved'), 'success');
68+
$this->redirect(array('action' => 'index'));
69+
} else {
70+
$this->Session->setFlash(__('The label could not be saved. Please, try again.'), 'error');
71+
}
72+
} else {
73+
$this->request->data = $this->Label->read(null, $id);
74+
}
75+
$photos = $this->Label->Photo->find('list');
76+
$this->set(compact('photos'));
77+
}
78+
79+
/**
80+
* delete method
81+
*
82+
* @param string $id
83+
* @return void
84+
*/
85+
public function delete($id = null) {
86+
if (!$this->request->is('post')) {
87+
throw new MethodNotAllowedException();
88+
}
89+
$this->Label->id = $id;
90+
if (!$this->Label->exists()) {
91+
throw new NotFoundException(__('Invalid label'));
92+
}
93+
if ($this->Label->delete()) {
94+
$this->Session->setFlash(__('Label deleted'), 'success');
95+
$this->redirect(array('action' => 'index'));
96+
}
97+
$this->Session->setFlash(__('Label was not deleted'), 'error');
98+
$this->redirect(array('action' => 'index'));
99+
}
100+
}

app/Controller/PhotosController.php

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
App::uses('AppController', 'Controller');
3+
/**
4+
* Photos Controller
5+
*
6+
* @property Photo $Photo
7+
*/
8+
class PhotosController extends AppController {
9+
10+
11+
/**
12+
* index method
13+
*
14+
* @return void
15+
*/
16+
public function index() {
17+
$this->Photo->recursive = 0;
18+
$this->set('photos', $this->paginate());
19+
}
20+
21+
/**
22+
* view method
23+
*
24+
* @param string $id
25+
* @return void
26+
*/
27+
public function view($id = null) {
28+
$this->Photo->id = $id;
29+
if (!$this->Photo->exists()) {
30+
throw new NotFoundException(__('Invalid photo'));
31+
}
32+
$this->set('photo', $this->Photo->read(null, $id));
33+
}
34+
35+
/**
36+
* add method
37+
*
38+
* @return void
39+
*/
40+
public function add() {
41+
if ($this->request->is('post')) {
42+
$this->request->data('Photo.user_id', $this->Auth->user('id'));
43+
if ($this->Photo->add($this->request->data)) {
44+
$this->Session->setFlash(__('The photo has been saved'), 'sucess');
45+
$this->redirect(array('action' => 'index'));
46+
} else {
47+
$this->Session->setFlash(__('The photo could not be saved. Please, try again.'), 'error');
48+
}
49+
}
50+
$users = $this->Photo->User->find('list');
51+
$labels = $this->Photo->Label->find('list');
52+
$this->set(compact('users', 'labels'));
53+
}
54+
55+
/**
56+
* edit method
57+
*
58+
* @param string $id
59+
* @return void
60+
*/
61+
public function edit($id = null) {
62+
$this->Photo->id = $id;
63+
if (!$this->Photo->exists()) {
64+
throw new NotFoundException(__('Invalid photo'));
65+
}
66+
if ($this->request->is('post') || $this->request->is('put')) {
67+
if ($this->Photo->save($this->request->data)) {
68+
$this->Session->setFlash(__('The photo has been saved'), 'success');
69+
$this->redirect(array('action' => 'index'));
70+
} else {
71+
$this->Session->setFlash(__('The photo could not be saved. Please, try again.'), 'error');
72+
}
73+
} else {
74+
$this->request->data = $this->Photo->read(null, $id);
75+
}
76+
$users = $this->Photo->User->find('list');
77+
$labels = $this->Photo->Label->find('list');
78+
$this->set(compact('users', 'labels'));
79+
}
80+
81+
/**
82+
* delete method
83+
*
84+
* @param string $id
85+
* @return void
86+
*/
87+
public function delete($id = null) {
88+
if (!$this->request->is('post')) {
89+
throw new MethodNotAllowedException();
90+
}
91+
$this->Photo->id = $id;
92+
if (!$this->Photo->exists()) {
93+
throw new NotFoundException(__('Invalid photo'));
94+
}
95+
if ($this->Photo->delete()) {
96+
$this->Session->setFlash(__('Photo deleted'), 'sucess');
97+
$this->redirect(array('action' => 'index'));
98+
}
99+
$this->Session->setFlash(__('Photo was not deleted'), 'error');
100+
$this->redirect(array('action' => 'index'));
101+
}
102+
}

0 commit comments

Comments
 (0)