Switching PHP Versions
There may be multiple versions of PHP (eg PHP 7.3 and PHP 5.6 both) running in server. Sometimes we may need to switch between them. $sudo a2dismod php5.6 $sudo a2enmod php7.3 $sudo service apache2 restart
There may be multiple versions of PHP (eg PHP 7.3 and PHP 5.6 both) running in server. Sometimes we may need to switch between them. $sudo a2dismod php5.6 $sudo a2enmod php7.3 $sudo service apache2 restart
<?phprequire_once ‘IP2Location.php’;$db = new IP2LocationDatabase(‘databases/IP2LOCATION-LITE-DB1.BIN’, IP2LocationDatabase::FILE_IO);$records = $db->lookup($_SERVER[‘REMOTE_ADDR’], IP2LocationDatabase::ALL);if($records[‘countryCode’] == ‘NP’) { header(‘Location: http://sugatshrestha.com.np’); exit;}?> Requirement: Install IP2Location PHP Module first.
<?php echo $this->Form->create(‘Drinks’);echo $this->Form->input(‘drink’, array(“onchange”=>”this.form.submit()”, “options”=> array( “Tea”=>”Tea”, “Coffee”=>”Coffee”, “Juice”=>”Juice” ), ’empty’ => ‘What would you like to have?’)); echo $this->Form->end(); ?>
Configure Cache in app/Config/bootstrap.php Cache::config(‘long’, array( ‘engine’ => ‘File’, ‘duration’ => ‘+1 hours’, ‘probability’ => 100, ‘path’ => CACHE . ‘long’ . DS,));cache file will be written in apptmpcachelongIn controller (ArticlesController) public function latest_news ($limit=NULL) { $data = Cache::read(‘latest_news’, ‘long’); if (!$data) { $data = array(‘fields’=>array(‘id’,’title’), ‘conditions’=>array(‘Article.published’=>1), […]
public function search(){ $query = $this->request->data[‘Articles’][‘search’]; $escapedQuery = $this->Article->getDataSource()->value($query); $data = $this->Paginator->paginate(‘Article’, array(“MATCH (Article.title) AGAINST ($escapedQuery)”) ); $this->set(‘articles’, $data); }
Following is the default cakephp paginator sorting label.<?php echo $this->Paginator->sort(‘company_id’); ?> We can change it as follows <?php echo $this->Paginator->sort(‘company_id’,’Name of the Company’); ?>
Programmr is an online interactive lab for students and enthusiasts to learn, practice and become proficient in programming. Programmrin one of the best online coding simulators.At Programmr you can code, compile & run projects right in the browser in almost any language. Code & run command-line programs, web applications, mobile […]
function visitorCount($date) { return $this->Visitorcounter->find(‘count’, array( ‘conditions’ => array(‘DATE(Visitorcounter.created)’ => $date) )); }
In view: /Articles/admin_add.ctp <style>#image_preview{ display:none; }</style><!– to display form –><?php echo $this->Form->create(‘ArticleImage’, array(“id”=>”uploadimage”,’type’=>’file’)); ?><div id=”image_preview”><img id=”previewing” src=”noimage.png” /></div><div id=”selectImage”><label>Select Your Image</label><br/><?php echo $this->Form->input(‘image’, array(‘id’=>’file’,’type’=>’file’)); ?> </div><?php echo $this->Form->submit(‘upload’, array(‘type’=>’submit’,”value”=>”Upload”, “class”=>”submit” )); ?> <div id=”message”></div> <?php echo $this->Form->end(); ?> <script>$(document).ready(function (e) {$(“#uploadimage”).on(‘submit’,(function(e) {e.preventDefault();$(“#message”).empty(); $.ajax({url: “<?php echo Router::url (array(‘controller’ => ‘Articles’, ‘action’ =>’image_upload’), […]
According to the sitepoint.com survey, the most promising frameworks for 2014 seem to be: Laravel Phalcon Symfony2 Yii and CodeIgniter seem to be sharing 4th place.CakePHP, Aura and Zend framework 2 share 5th place.Source: http://www.sitepoint.com/best-php-frameworks-2014