<?php $ultraFastFrontend = new Phalcon\Cache\Frontend\Data(array( "lifetime" => 3600 )); $fastFrontend = new Phalcon\Cache\Frontend\Data(array( "lifetime" => 86400 )); $slowFrontend = new Phalcon\Cache\Frontend\Data(array( "lifetime" => 604800 )); //Backends are registered from the fastest to the slower $cache = new \Phalcon\Cache\Multiple(array( new Phalcon\Cache\Backend\Apc($frontCache, array( "prefix" => 'cache', )), new Phalcon\Cache\Backend\Memcache($fastFrontCache, array( "prefix" => 'cache', "host" => "localhost", "port" => "11211" )), new Phalcon\Cache\Backend\File($slowestFrontCache, array( "prefix" => 'cache', "cacheDir" => "../app/cache/" )); )); // , $cache->save('my-key', $data); // , $data = $cache->get('my-key');
{# #} {{ total > 0 ? total|format('%0.2f') : '0.0' }} {# For-Else #} {% for robot in robots %} {{ robot.name }} {% else %} There are no robots {% endfor %} {# #} <table> {% for robot in robots %} {% if loop.first %} <thead> <tr> <th>Position</th> <th>Id</th> <th>Name</th> </tr> </thead>ae <tbody> {% endif %} <tr> <th>{{ loop.index }}</th> <th>{{ robot.id }}</th> <th>{{ robot.name }}</th> </tr> {% if loop.last %} <tbody> {% endif %} {% endfor %} </table> {# (Space control delimiters) #} <ul> {%- for robot in robots -%} <li> {{- robot.name -}}</li> {%- endfor %} </ul>
class Robots extends Phalcon\Mvc\Model { public function initialize() { $this->setReadConnectionService('dbSlave'); $this->setWriteConnectionService('dbMaster'); } }
class Robots extends Phalcon\Mvc\Model { public function selectReadConnection($intermediate, $bindParams, $bindTypes) { // , 'where' if (isset($intermediate['where'])) { $conditions = $intermediate['where']; // if ($conditions['left']['name'] == 'id') { $id = $conditions['right']['value']; if ($id > 0 && $id < 10000) { return $this->getDI()->get('dbShard1'); } if ($id > 10000) { return $this->getDI()->get('dbShard2'); } } } // return $this->getDI()->get('dbShard0'); } }
class Robots extends Phalcon\Mvc\Model { public function initalize() { $this->keepSnapshots(true); } }
$robot = new Robots(); $robot->name = 'Other name'; var_dump($robot->getChangedFields()); // ['name'] var_dump($robot->hasChanged('name')); // true var_dump($robot->hasChanged('type')); // false
class Robots extends Phalcon\Mvc\Model { public function initalize() { $this->useDynamicUpdate(true); } }
$validation = new Phalcon\Validation(); $validation ->add('name', new PresenceOf(array( 'message' => ' name ' ))) ->add('name', new StringLength(array( 'min' => 5, 'minimumMessage' => ' name ' ))) ->add('email', new PresenceOf(array( 'message' => ' email ' ))) ->add('email', new Email(array( 'message' => 'Email ' ))) ->add('login', new PresenceOf(array( 'message' => ' login ' ))); $messages = $validation->validate($_POST); if (count($messages)) { foreach ($messages as $message) { echo $message; } }
git clone http://github.com/phalcon/cphalcon cd build git checkout 1.0.0 sudo ./install
Source: https://habr.com/ru/post/171915/
All Articles