Skip to main content


Showing posts from 2013

Apache and mod_rewrite (and .htaccess) in Ubuntu

To enable mod_rewrite in Ubuntu, you just need to write this command in terminal

sudo a2enmod rewrite

Restart your your apache.

sudo service apache2 restart

After enabling mod_rewrite you can write .htaccess file for your web application.

CakePHP | URL Rewrites on IIS7 (Windows hosts / Azure)

IIS7 does not natively support .htaccess files. While there are add-ons that can add this support, you can also import htaccess rules into IIS to use CakePHP’s native rewrites. To do this, follow these steps:

1. Create a new file in your CakePHP root folder, called Web.config.
     /site/wwwroot/    or  /site/wwwroot/cakefolder/ or outside of your app   directory

2. Paste this rule to your Web.config.

<?xmlversion="1.0"encoding="UTF-8"?><configuration><system.webServer><rewrite><rules><clear/><rulename="Imported Rule 0"stopProcessing="true"><matchurl="^(img|css|files|js)(.*)$"></match><actiontype="Rewrite"url="app/webroot/{R:1}{R:2}"appendQueryString="false"></action></rule><rulename="Imported Rule 1"stopProcessing="true"><matchurl="^(.*)$"ignoreCase="false" /><conditionslogicalGr…

CakePHP: COUNT data and GROUP BY date

Goal: Count Tip Offs created per day for a month to use for graph
Problem: created field name is in datetime format: Y-m-d H:i:s
Solution: format SQL Query date: DATE_FORMAT(TipOff.created, '%Y-%m-%d')

Inside the function of controller
<?php$tipOffsMonthly=$this->TipOff->find('all', array('conditions'=>array('AND'=>array('TipOff.electric_cooperatives_id'=>AuthComponent::User('electric_cooperatives_id'), 'TipOff.created BETWEEN ? AND ?'=>array($first_day, $last_day))), 'fields'=>array("COUNT('created') as per_day", 'created'), 'group'=>array("DATE_FORMAT(TipOff.created, '%Y-%m-%d')") ));?>

Hostinger | Free Web Hosting with PHP and MySQL, Website Builder, No Ads


New generation of free hosting Forget stereotypes about free web hosting. Hostinger is different. We provide reliable and feature rich hosting with fanatic user support! Our service uptime is 99.9% - thanks to cloud computing technology we utilize.
PHP and MySQL Support We support PHP and MySQL without any restrictions. Our PHP engine comes with all features and functions enabled. You can switch to any PHP version in one click and manage databases with phpMyAdmin tool. No ads or banners on your pages No text links. No annoying pop-ups. No annoying banners. No mandated forum posting. Your web site will be 100 percent ad free forever. Software auto installer Just with a few clicks you may install Wordpress, Joomla, PrestaShop, phpBB, Drupal and may other scripts. Fully functional and professional looking web site can be setup in minutes. Easy to use website builder You can now build your site very easy. Even computer newbie can create a nice looking website with our …

CakePHP : Load Model from other Controller

In your Controller were you want to load the model.

<?php  App::import('Controller');class ReportsController extends AppController {publicfunction other_reports(){//this will load other model $this->loadModel('OtherModel');$otherModels=$this->OtherModel->find('all');$this->set('otherModels',$otherModels);}}?>

CakePHP: Calling function from other controller

Import Controller of the function you want to use.

Once you imported  the controller you can call any function of this controller.

<?php//Import controller  App::import('Controller','SmsOutgoings');class ReportsController extends AppController {publicfunctionadd(){$message="Notification: New report submitted!";//Instantiation$SmsOutgoings=new SmsOutgoingsController;//Call a method from SmsOutgoingsControllerwith parameter$SmsOutgoings->notify_user($user_id,$message);}}?> Other way is by using the requestAction() function
<?phpclass ReportsController extends AppController {publicfunctionadd(){$message="Notification: New report submitted!";//Call a method from SmsOutgoingsController with parameter$this->requestAction('/sms_outgoings/notify_user',array($user_id,$message))

CakePHP : Updating the session user data after edit

//users controller

if ($this->User->save($this->request->data)) {
if($this->request->data['User']['id'] == AuthComponent::User('id')){ //if current logged in user  update user session data

                  $this->Session->write('Auth.User.first_name', $this->request->data['User']['first_name']); //updating first_name only

                  $this->Session->write('Auth.User.username', $this->request->data['User']['username']); //updating username only

                  $this->Session->write('Auth.User', array_merge(AuthComponent::User(), $this->request->data['User']) );   //updating all user session data

                $this->Session->setFlash('The user has been saved');
                $this->Session->setFlash('', 'default', array(), 'success');