
afterFind(), beforeValidate(), afterValidate(), beforeSave(), afterSave(), beforeDelete(), afterDelete(), and onError().echo Configure::version()
VERSION.txt file/path/to/cake/lib/Cake/VERSION.txt
FileEngine : Uses simple files to store content. Poor performance, but good for storing large objects, or things that are not IO sensitive.ApcEngine : Uses the APC object cache, one of the fastest caching engines.MemcacheEngine : Uses the PECL::Memcache extension and Memcached for storage. Fast reads/writes, and benefits from memcache being distributed.XcacheEngine : Uses the Xcache extension, an alternative to APC.WincacheEngine : Uses Windows Cache Extension for PHP. Supports wincache 1.1.0 and higher.hasOne : One to One RelationshiphasMany : One to many RelationshipbelongsTo : Many to One RelationshiphasAndBelongsToMany(HABTM) : Many to Many Relationshipecho $this->Html->url(null, true);http://localhost/project/controller/action/1save() function to insert or update the data into the database.delete() function, you can do different delete types like cascading delete, bulk delete, strict delete with the data.get() or find() function, you can retrieve the data. With the first() function, you can retrieve the resulting set.static Cake\Utility\Security::hash($string, $type = NULL, $salt = false)
use Cake\Validation\Validator;
$validator = new Validator();
| Logging level | Description |
|---|---|
| Emergency | System is unusable. |
| Alert | Action must be taken immediately. |
| Critical | Critical conditions |
| Error | Error conditions |
| Warning | Warning conditions |
| Notice | Normal but significant condition |
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'you@localhost',
],
],
Helper::beforeRender(Event $event, $viewFile)
Helper::beforeRenderFile(Event $event, $viewFile)
Helper::afterRender(Event $event, $viewFile)
Helper::afterLayout(Event $event, $layoutFile) etc.
Security::encrypt($text, $key, $hmacSalt = null)
$hmacSalt() is the salt to use for HMAC process. Null is used to defined to use Security.saltSecurity::cipher() function.Security::encrypt($text, $key, $hmacSalt = null)
$key is the 256 bit/32 byte cipher key or Security.cipherSeed$this->set('variable','value')
$this->set(compact('varible1','variable2','variable2',.......));
Session::read($key)function is used to read specific session data in CakePHP.$this->Session->read('MysessionVar');
Session::write($key, $value)function is used to write session data in CakePHP.$this->Session->write('MysessionVar', "Hello");
* Session::delete($key)function is used to delete specific session data in CakePHP.
$this->Session->delete('MysessionVar');
<?php
class User extends AppModel {
var $name = 'User';
var $validate = array();
}
?>
<?php
class User extends AppModel {
var $name = 'User';
var $validate = array(
'login' => 'alphaNumeric',
'email' => 'email',
'born' => 'date'
);
}
?>
App::import('Sanitize');
class MyController extends AppController {
...
...
}
$badString = ";:<script><html>< // >@@#";
echo Sanitize::paranoid($badString);
// output: scripthtml
echo Sanitize::paranoid($badString, array(' ', '@'));
// output: scripthtml @@
$badString = '<font size="99" color="#FF0000">HEY</font><script>...</script>';
echo Sanitize::html($badString);
// output: <font size="99" color="#FF0000">HEY</font><script>...</script>
echo Sanitize::html($badString, true);
// output: HEY...
escape(string $string, string $connection)app/config/database.php file.Sanitize::clean(mixed $data, mixed $options)config() method.$this->Cookie->config([
'expires' => '+5 days',
'httpOnly' => true
]);
php composer.phar create-project --prefer-dist cakephp/app my_app_name.ctp is the default extension of the view file. You can change default extension to write public $ext = '.yourextension' in AppController. If you want to change it for a particular controller, then add it to that particular Controller only.var $layout = 'layout_name';
$this->layout ="layout_name";
public $helpers = array('Form', 'Html', 'Js', 'Time');
$this->helper[] ="helper_name";
public $components = array('Emails', 'ImageUploader', 'Sms');
url( string|array|null $url null , boolean $full false )
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class ArticlesTable extends Table
{
}
public function someMethod()
{
$resultset = $this->fetchTable('Articles')->find()->all();
foreach ($resultset as $row) {
echo $row->title;
}
}
use Cake\ORM\Locator\LocatorAwareTrait;
public function someMethod()
{
$articles = $this->getTableLocator()->get('Articles');
// more code.
}
$articles = TableRegistry::getTableLocator()->get('Articles');src/Model/Entity/Article.php after the <?php opening tag :namespace App\Model\Entity;
use Cake\ORM\Entity;
class Article extends Entity
{
}
use Cake\ORM\Locator\LocatorAwareTrait ;
$articles = $this->getTableLocator()->get('Articles');
$resultset = $articles->find()->all();
foreach ($resultset as $row) {
// Each row is now an instance of our Article class.
echo $row->title;
}
entityClass() method to set a specific classname.class Cake\Utility\InflectorInflector::pluralize('example') returns “examples”.| Method | Argument | Output |
|---|---|---|
|
|
BigApple |
BigApples |
|
big_apple |
big_apples |
|
|
|
BigApples |
BigApple |
|
big_apples |
big_apple |
|
|
|
big_apples |
BigApples |
|
big apple |
BigApple |
|
|
|
BigApples |
big_apples |
|
Big Apples |
big apples |
|
|
|
big_apples |
Big Apples |
|
bigApple |
BigApple |
|
|
|
big_apples |
BigApple |
|
big apple |
BigApple |
|
|
|
BigApples |
big-apples |
|
big apple |
big apple |
|
|
|
BigApple |
big_apples |
|
Big Apple |
big apples |
|
|
|
big_apple |
bigApple |
|
big apples |
bigApples |
<registry-object>() Example :$this->loadComponent('Acl.Acl');
$this->addHelper('Flash')
on-the-fly. Example:$this->loadComponent('Cookie', ['name' => 'sweet']);
$this->Auth = $this->loadComponent('Auth', ['className' => 'MyCustomAuth']);
$this->Auth->user(); // Actually using MyCustomAuth::user();
// Remove Auth from callbacks.
$this->getEventManager()->off($this->Auth);
// Re-enable Auth for callbacks.
$this->getEventManager()->on($this->Auth);