Tips in Cakephp

1) Fatal error: Class app not found in
some time i had face a error i had create a table " locations" related to cities, then create a Model "locations" and when i use that model inside a controller i got following
Fatal error: Class "Location" not found ! . i checked thoroughly and found that Model name is in pural.. so i change the Model name from "Locations" to "Location" and error is gone !.


2) How to get WAN IP from PHP

I understand it, on a typical LAN setup, where the entire LAN is connected to the internet via a router, each computer on the LAN would share a "external", WAN IP (assigned to the router), but each of them would have a "internal", LAN IP (typically 192.168.*.*).
In that scenario, all external requests by any computer on that LAN would appear to come from the same WAN IP. The router alone would be aware of which computer on the LAN the request belongs to, so there would be no way for your PHP to detect the LAN IP, but only the WAN IP (via the $_SERVER['REMOTE_ADDR'] element).
If the request is internal (like say to a HTTP server on the same LAN), the $_SERVER['REMOTE_ADDR'] element would retain the LAN IP of the computer that made the request.
In short, the server only knows the IP of the device that sent the request, regardless of whether that IP belongs to a LAN, WAN or any other sort of network.

3) Controller Function to open download dialogbox


function downloadexcel(){

$this->load->model('config_model');
$filename = "import_mulitple_user.xls";
$temp=$_SERVER['SCRIPT_NAME']; //**dzine-discoverself/index.php
$temp=explode("/",$temp);
$maindir=$temp[1]; //** dzine-discoverself
$path = $_SERVER['DOCUMENT_ROOT'].'/'.$maindir.'/'.$filename;

header('Content-Transfer-Encoding: binary');  // For Gecko browsers mainly
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Accept-Ranges: bytes');  // For download resume
header('Content-Length: ' . filesize($path));  // File size
header('Content-Encoding: none');
header('Content-Type: application/xls'); 
 // Change this mime type if the file is not PDF
header('Content-Disposition: attachment; filename=' . $filename);  
// Make the browser display the Save As dialog
exit();

}