CakePHP est un framework libre écrit en PHP. Il suit le motif de conception Modèle-Vue-Contrôleur et imite le fonctionnement de Ruby on Rails.
http://cherryonthe.popnews.com/ (thanks rodn!)
intéressant aussi, permet d'installer un serveur cake rapidement:
http://bakery.cakephp.org/articles/view/the-cakephp-instaweb-webserver
sudo apt-get install cakephp-instaweb
cakephp-instaweb
sudo apt-get install cakephp cakephp-instaweb cakephp-scripts php5 python-twisted-bin python-twisted-core python-twisted-web python-zopeinterface bake
source: http://bakery.cakephp.org/articles/view/installing-cakephp-on-ubuntu
1.Ensure mod-rewrite is enabled by running the following command:
sudo a2enmod rewrite
If mod-rewrite is not enabled, follow the on-screen instructions to install it.
2.Next, edit the site config file for which you want to enable mod-rewrite. This is likely to be /etc/apache2/sites-available/default. Edit the file as root using your text editor of choice (try sudo Nano default)
3.Add the following entry:
AllowOverride All
http://cakephp.org/downloads/index/nightly
unzip it to webserver, eg /home/radeff/www/cake
setup permissions:
chmod 777 /var/www/cake/app/tmp/cache/ #create a symlink in your $HOMEDIR ln -s /var/www/cake ~ cd ~/cake chmod 777 app/tmp/
si vous avez le message:
Notice (1024): Please change the value of 'Security.salt' in aa01/config/core.php to a salt value specific to your application [CORE\cake\libs\debugger.php, line 535]
The security salt is used for generating hashes, particularly for password security. The Cake build has a default salt which should be changed otherwise there is the potential that another site with the same build and thus the same default salt could be well on the way to crack your passwords. Note that the first Cake bake pass should have modified this salt, but you can manually change it. Sometimes I manually generate a project salt based on the project name and build version so that I can check it during subsequent processing. Change one or more characters of the salt or generate yourself a completely new salt. Use something like echo sha1(’my own security salt string’) and copy the 40 character hashed string. The security.salt is stored in \htdocs\aa01\config\core.php at around line 153.
vi /home/radeff/cake/app/config/core.php /Security.salt :x
et chez moi c'était OK
pour que les css etc s'affichent correctement il faut autoriser le mod_rewrite d'apache et redémarrer le serveur web:
#lien symbolique
/etc/apache2/mods-enabled# ln -s ../mods-available/rewrite.load
sudo ln -s /etc/apache2/mods-available/userdir.load /etc/apache2/mods-enabled/userdir.load
sudo ln -s /etc/apache2/mods-available/userdir.conf /etc/apache2/mods-enabled/userdir.conf
#j'ai du ajouter dans mon apache.conf
<Directory "/var/www/cake/">
AllowOverride All
</Directory>
#restart server
/etc/init.d/apache2 restart
Pour bosser ensuite on peut utiliser tout éditeur, mais le mieux semble eclipse
Chez infomaniak, c'est simple: dans la racine du cake, placer un htaccess (dans l'exemple protégé par un mdp, vous pouvez supprimer tout ce qui est avant ifmodule si pas nécessaire):
AuthType Basic AuthName Restricted Require user cocagne AuthUserFile /home/www/YOURINFOMANIAKPATH/.htpasswd AuthGroupFile /home/www/YOURINFOMANIAKPATH/.htgroup <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>
http://www.infomaniak.ch/guide/french/htaccess/ plus d'infos sur htaccess chez infomaniak
http://book.cakephp.org/ The official Manual
http://book.cakephp.org/fr/ en français siouplé
http://bakery.cakephp.org/ cf aussi http://bakery.cakephp.org/tags/view/cake
http://www.formation-cakephp.com/
http://cakeforge.org/projects/cakedocs/
http://groups.google.com/group/cake-php
http://www-128.ibm.com/developerworks/edu/os-dw-os-php-cake1.html
http://www-128.ibm.com/developerworks/edu/os-dw-os-php-wiki1.html
Des CMS écrits en cake se développent rapidement, quelques liens:
http://planetcakephp.org/aggregator/items/1054-simple-cakephp-cms-content-management-system
http://planetcakephp.org/aggregator/items/3543-5-cakephp-based-content-managament-system
http://cupcakecms.sourceforge.net/index.html
episode un russe pour faire bonne mesure
Tutifrutti commercial
http://marcgrabanski.com/article/cakephp-ajax-quick-save-jquery
http://bakery.cakephp.org/articles/view/easy-ajax-pagination-using-jquery
http://blogfreakz.com/cakephp/cakephp-jquery-autocomplete-tutorial/
Autocomplete en Ajax (autofill)
http://set4net.org/blog/2010/11/cakephp-%E2%80%93-jquery-autocomplete-tutorial/
Others http://www.nodstrum.com/2007/09/19/autocompleter/
http://www.jensbits.com/2010/03/29/jquery-ui-autocomplete-widget-with-php-and-mysql/
http://book.cakephp.org/view/327/simple-user-authentication commencer par là
INSERT INTO `users` (`id`, `login`, `password`, `disabled`, `created`) VALUES (1, 'admin', SHA1('6a10cdde80fb56150efda09365f91579ea74a944admin'), 0, NOW());
http://www.jamesfairhurst.co.uk/posts/view/creating_an_admin_section_with_cakephp
http://bakery.cakephp.org/articles/search/2/authentication
http://bakery.cakephp.org/articles/view/obauth-simple-authentication
Un bon livre: Beginning CakePHP: From Novice to Professional GOLDING David 2008
http://forum.jeanviet.info/discussion/66/google-analytics-avec-lapi-php-cakephp/
http://code.google.com/intl/fr/apis/ajaxlanguage/
http://code.google.com/intl/fr/apis/ajaxlanguage/documentation/
http://thechaw.com/api_generator ???
http://code.google.com/p/php-language-api/
http://snipplr.com/view/15538/google-ajax-libraries-api-handler-for-cakephp/
cake php project (bouquin)
http://www.sitepoint.com/article/application-development-cakephp
http://www.journaldunet.com/developpeur/tutoriel/php//070403-php-cakephp-framework/0.shtml
http://www.jamesfairhurst.co.uk/posts/view/full_cakephp_application_part_6 plusieurs tutoriaux intéressants, notamment sur les login
<?php echo $html->link( $html->image('/img/loupe.jpg', array("alt" => "Détail", "title"=>"Détail")), array('action'=>'view', $saisy['Saisy']['id']), array('escape' => false)); ?>
http://www.reversefolds.com/articles/show/ajax
Getting started quickly with Scriptaculous effects
voir aussi sur ce wiki scriptaculous
bof http://mhjewel.wordpress.com/2008/01/26/my-first-project-with-cakephp-and-scriptaculous-framework/
Using TinyMCE with CakePHP and AJAX
petite démo, mieux vaut
il faut suivre le tutoriel pour créer un blog, qui demandera les commandes suivantes:
~/cake/app/config cp database.php.default database.php vi database.php #faire les modifs #créer le premier controleur ~/cake/app/models gedit post.php #copier/coller/sauver/sortir cd ../controllers/ gedit posts_controller.php #copier/coller/sauver/sortir ~/cake/app/views mkdir posts gedit index.ctp #copier/coller/sauver/sortir http://localhost/cake/posts
faut changer les droits dans le cache:
chmod -R 777 /var/www/cake/app/tmp/cache
Dans “Validation rule”, on parle du fichier models/post.php
pas s'inquiéter si la suite marche pas, faut voir l'ancienne version (en date du — Fred Radeff 2008/07/10 12:58)
Pour utiliser les fonctions scaffold de cakephp, qui permettent de construire une application en 5 minutes chrono à partir d'une base de données, suivre cet exemple: Copie locale de http://www.grahambird.co.uk/cake/tutorials/scaffolding.php
Ensuite, pour montrer la puissance de cakephp, faire une modification dans la base de données et recharger l'exemple, vous verrez alors toute l'application s'adapter à la nouvelle structure de la table
ALTER TABLE `bookmarks` ADD `category` VARCHAR( 255 ) NOT NULL AFTER `url` ;
voir aussi si on veut faire des JOIN tables
http://www.developer.com/lang/php/article.php/3636686
CREATE TABLE players ( id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(50) NOT NULL, position VARCHAR(25) NOT NULL, team_id SMALLINT(6) ) CREATE TABLE teams ( id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, )
faire un moteur de recherche avec cakephp
http://manual.cakephp.org/view/313/Controllers
Livesearch (Ajax style search) essayé mais planté
http://www.littlehart.net/atthekeyboard/2007/08/07/stupid-cakephp-controller-tricks/ pas trouvé mais trucs intéressants
http://www.scribd.com/doc/5545/CakePHP-tutorial-no-2-from-IBM tutoriel IBM pas trouvé (mais pas trop cherché)
http://code.google.com/p/searchable-behaviour-for-cakephp/
http://bakery.cakephp.org/articles/view/search-feature-to-cakephp-blog-example marche mais plante à la fin
http://stackoverflow.com/questions/327052/cakephp-find-based-on-habtm-relationship un exemple ou un modèle appelle plusieurs tables relationnelles, à creuser pour ergolang (categories communes à tous les vocabulaires)
voir aussi
http://book.cakephp.org/view/73/Retrieving-Your-Data
http://teknoid.wordpress.com/2008/07/03/notes-on-cakephp-habtm-part-1-the-basics/
Cake propose toute une série de validations, y compris en ligne de commande (bake)
http://book.cakephp.org/view/134/Core-Validation-Rules
Un truc qui m'a pris la tête: avoir plus d'une validation pour un champ
En fait c'est assez simple, cf http://jamnite.blogspot.com/2009/05/cakephp-form-validation-with-ajax-using.html
<?php class Post extends AppModel { var $name = 'Post'; var $validate = array( 'title' => array( 'required' => array('rule' => 'notEmpty'), 'maxlength' => array('rule' => array('maxLength', 30)) ), 'body' => array( 'required' => array('rule' => 'notEmpty'), 'maxlength' => array('rule' => array('maxLength', 200)) ) ); } ?>
ici les champs title et body sont à la fois requis ET ont une longueur max; comme d'habitude, faut faire des array dans des array… pas encore trop l'habitude!
non, marche pas
mieux vaut utiliser cette solution:
'paper_title' => array( 'This field cannot be left blank' => array('rule' => 'notempty'), 'max. 250 characters' => array('rule' => array('maxLength', 250)), ),
attention la validation par défaut marche PAS!!!
http://planetcakephp.org/aggregator/items/3150-cakephp-%E2%80%93-email-validation
After working for about one year, the BHJS Alumni website phase 2 is completed. But after it is deployed in production server, i found that some email addresses are regarded as invalid email address. The email validation rule which i used is provided by CakePHP. Only email addresses ended with .com, .org etc… could pass the validation rule.
So i ask the Google teacher and luckily i am not the only one to come across this problem.
Email Validation in cakephp
What i can do is writing my own validation rule which can be doned by regular expression in the model.php. Again, Google is really helpful and there are many regular expressions for email validation. Finally, i pick the following one.
^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\.)+([A-Za-z0-9]{2,4}|museum)$
Reference: TIP: Simple Regular Expression for Email Validation
And so in the model.php, i replaced the email validation as follow.
var $validate = array(
'id' => array('numeric'),
/* CakePHP has problem on email validate. Reference: http://groups.google.com.tw/group/cake-php/browse_thread/thread/3d0a47d4...
'email_address' => array('notempty', 'email' => array('rule' => array('email', true),'message' => 'Please supply a valid email address.')),
*/
// The following change is done for the above problem. Reference: http://gofedora.com/tip-simple-regular-expressi-email-validation/
'email_address' => array('notempty', 'email' => array('rule' => '/^[A-Za-z0-9._%+-]+@([A-Za-z0-9-]+\.)+([A-Za-z0-9]{2,4}|museum)$/','message' => 'Please supply a valid email address.'))
);
pour générer du code en bash avec cake:
sudo apt-get install cakephp1.3-scripts
puis voir doc sous http://book.cakephp.org/fr/view/113/code-generation-with-bake
http://www.formation-cakephp.com/40/console-ligne-de-commande
cake bake db_config cake bake model cake bake view cake bake controller cake bake project cake bake test cake bake all cake bake controller Users
http://www.webdevelopment2.com/cakephp-bake-baking-models-controllers-views-cakephp-12/
si ça coince: http://grasshopperpebbles.com/ubuntu/cakephp-baking-on-ubuntu/
echo $PATH echo 'export PATH=/home/les/public_html/cake/cake/console:$PATH' >> ~/.profile . .profile cake
You can go through all the prompts, but in my opinion this takes too much time for me. Here are some straight to the point commands to get you on your way:
cake bake controller Users
This bakes an empty controller using scaffolding. If you don’t know, Scaffolding is sort of like baking, except with no functions and no views. This is usually used to test of database schema, model association, model validation, etc.
cake bake controller Users scaffold
This does the same thing as the command above, except it actually creates the functions: index, add, view, edit, and delete.
cake bake controller Users scaffold admin
Again, this does the same thing as the top, but with admin_index, admin_add, admin_view, admin_edit and admin_delete functions. Starting to get the picture?
This couldn’t be simpler:
cake bake view Users
Creates views for all the functions created in the Users controller.
To generate only the admin functions you have to provide “null” instead of “scaffold”:
cake bake controller Users null admin
With the “all” parameter it is now possible to bake with one command a model plus the corresponding controller with its views:
cake bake all // asks you for the model name cake bake all User
Il semble qu'eclipse soit le plus populaire, mais j'utilise pas mal aussi emacs pour les expressions régulières et quanta:
Utiliser Quanta avec cake: http://forum.cakephp-fr.org/viewtopic.php?id=22 (voir aussi autres liens, eg. http://groups.google.com/group/cake-php/browse_thread/thread/efc0a080cceb37f5/700861ec9b4151b8
CakePHP est pauvre en templates, mais potentiellement très riche puisqu'il s'adapte à des moteurs de templates comme joomla
http://jeremydorn.blogspot.com/2008/10/site-templates-with-cakephp.html
en gros: on télécharge un template p. ex. sur http://www.oswd.org/designs/browse/
on adapte default.ctp avec le bon css et les éléments cake, p.ex.
<!-- Main Site Content --> <?php $session->flash(); echo $content_for_layout; ?>
kw: Langue / Language / i18n / traduction / translation
outre i18n, on peut aussi faire plus moche mais aussi efficace avec du replace - p. ex. si le i18n tourne pas sur votre serveur
dans le modèle:
class Exercice extends AppModel {
var $name = 'Exercice';
...
/*trim posted values*/
function beforeSave() {
$this->data['Exercice']['titreexercice']=trim($this->data['Exercice']['titreexercice']);
$this->data['Exercice']['soustitre']=trim($this->data['Exercice']['soustitre']);
$this->data['Exercice']['liengrammaire']=trim($this->data['Exercice']['liengrammaire']);
$this->data['Exercice']['debutcontenu']=trim($this->data['Exercice']['debutcontenu']);
$this->data['Exercice']['fincontenu']=trim($this->data['Exercice']['fincontenu']);
$this->data['Exercice']['source']=trim($this->data['Exercice']['source']);
return true;
}
echo "<select id=\"CmTypeId\" name=\"data[Cm][type_id]\">"; /* Type */ $i=0; while($i<mysql_num_rows($sqlq)){ echo "<option value=\"" .mysql_result($sqlq,$i,'id')."\""; if($form->value('type_id')==mysql_result($sqlq,$i,'id')) { echo " selected"; } echo ">" .mysql_result($sqlq,$i,'lib'); echo "</option>"; $i++; } echo "</select>";
pour avoir toutes les sessions:
print("<pre>"); print_r($_SESSION); print("</pre>");
pour récupérer le contenu d'une variable session (style php): MARCHE PARTOUT
$auth_role=$_SESSION['Auth']['User']['group_id'];
Utiliser meioupload, installé en 5'
rm -fR tmp/cache/persistent/* rm -fR tmp/cache/models/* rm -fR tmp/cache/views/*
function add() { if (!empty($this->data)) { $this->Remarque->create(); if ($this->Remarque->save($this->data)) { #$this->flash(__('Remarque saved.', true), array('action'=>'index')); $this->redirect(array('action'=>'index'), null, true); } else { } } } function edit($id = null) { if (!$id && empty($this->data)) { $this->flash(__('Invalid Remarque', true), array('action'=>'index')); } if (!empty($this->data)) { if ($this->Remarque->save($this->data)) { #$this->flash(__('The Remarque has been saved.', true), array('action'=>'index')); $this->redirect(array('action'=>'index'), null, true); } else { } } if (empty($this->data)) { $this->data = $this->Remarque->read(null, $id); } }
Il est possible d'intégrer cake et joomla, plus d'infos: cake_joomla
J'ai eu beau essayer chez infomaniak, j'y suis toujours pas parvenu, par contre sur des serveurs ou je peux travailler en root pas de problème: il suffit de faire une installation d'un cake, puis de placer des app/ ailleurs et d'y modifier webroot/index.php
ROOT /user/home APP_DIR www CAKE_CORE_INCLUDE_PATH user/home
if (!defined('ROOT')) { define('ROOT', DS.'user'.DS.'home'); } if (!defined('APP_DIR')) { define('APP_DIR', 'www'); } if (!defined('CAKE_CORE_INCLUDE_PATH')) { define('CAKE_CORE_INCLUDE_PATH', DS.'user'.DS.'home'); }
http://ajbrown.org/blog/2008/12/22/four-reasons-to-hate-cakephp/
caddie - basket - panier - ecommerce
http://cakeforge.org/projects/bakesale/
composant versionning cake http://bakery.cakephp.org/articles/view/revision-behavior-revision-control-made-easy
top et simple: permet de gérer les versions en faisant simplement une copie de la table et UNE ligne dans le model
http://book.cakephp.org/fr/view/165/Controller-Setup
le plus simple, ajouter au début du controller local:
class DonneesController extends AppController { #criteres de tri var $paginate = array( 'limit' => 25, 'order' => array( 'Donnee.NOM' => 'asc' ) );
Mais méchant défaut: il ne conserve pas les GET / POST lors de motifs de recherche, à proscrire donc! Suivre la méthode décrite ici copie locale | fichier tar modifié par mes soins - version française