Skip to main content

Posts

Cakephp testimonials

CakePHP testimonials Components and Plugins are still separate entities in Cake 2.0. According to the manual components are " are packages of logic that are shared between controllers ", whereas plugins are "a combination of controllers, models, and views". Compoments extend the base Component class, while Plugins have their own AppModel and AppController. Think of a plugin as a separate Cake application sharing the same core libraries with your main application. How to use vendor in cakephp App::import('Vendor', 'Custom/getdata'); $obj = new GetData(); Lib Contains 1st party libraries that do not come from 3rd parties or external vendors. This allows you to separate your organization’s internal libraries from vendor libraries. Vendor Any third-party classes or libraries should be placed here. Doing so makes them easy to access using the App::import(‘vendor’, ‘name’) function. Keen observers will note that this seems redundant, as ther...

Cakephp redirection

CakePHP Redirection Redirecting: $this->redirect(array('controller' => 'orders', 'action' => 'thanks')); Redirecting to website: $this->redirect('http://www.example.com'); Render the element for ajax: $this->render('/Elements/ajaxreturn'); Redirect to 404 not found: throw new NotFoundException('404 Error - Page not found'); If you need to redirect to the referer page you can use: $this -> redirect ( $this -> referer ()); If you need to redirect to the edit page with id: $this -> redirect ( array ( ’action’ => ’edit’ , $id )); Redirect to different action: $this -> render ( ’custom_file’ ); Call element in controller action $this->viewPath = 'Elements'; $this->render('sub_cat_list');       

Cakephp Model Query

Cakephp Model Fetch query Retrieve data from database $this->Resume->find('first',array('contain'=>array('ResumeSkill'=>array('Skill'=>array('name'), 'conditions'=>array('ResumeSkill.skill_id !='=>''))), 'conditions'=>array('Resume.user_id'=>$user_id),'order'=>'Resume.modified DESC')); $this->Layout->query("SELECT *,if(sort IS NULL,0,sort) as sort1  FROM `layouts` AS Layout WHERE `user_id` LIKE '".$user_id."' && Layout.active=1 ORDER BY (`sort1`>0) DESC,(`sort1`) ASC"); $this->Invoice->find('first',array('fields'=>array('*','curdate() as curdate','DATE_FORMAT(plan_start_date,"%Y-%m-%d") as plan_start_date1'), 'conditions'=>array('Invoice.id'=>$last_invoice_id,'Invoice.user_id'=>$this->Auth->user('id') ,...

Jquery Ajax method

AJAX = Asynchronous JavaScript and XML. AJAX is about loading data in the background and display it on the webpage, without reloading the whole page. The ajax() method is used to perform an AJAX (asynchronous HTTP) request. Notes: Asynchronous means that the script will send a request to the server, and continue it's execution without waiting for the reply. As soon as reply is received a browser event is fired, which in turn allows the script to execute associated actions. The serialize() method creates a URL encoded text string by serializing form values readyState  Holds the status of the XMLHttpRequest. Changes from 0 to 4: 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready The parameters specifies: beforeSend(xhr): A function to run before the request is sent eg: beforeSend: function() {     xhr.setRequestHeader("Accept", "text/javascr...

Fetch IP address & country

Function to fetch ip address function get_ip() { $ipaddress = ''; if (getenv('HTTP_CLIENT_IP')) $ipaddress = getenv('HTTP_CLIENT_IP'); else if(getenv('HTTP_X_FORWARDED_FOR')) $ipaddress = getenv('HTTP_X_FORWARDED_FOR'); else if(getenv('HTTP_X_FORWARDED')) $ipaddress = getenv('HTTP_X_FORWARDED'); else if(getenv('HTTP_FORWARDED_FOR')) $ipaddress = getenv('HTTP_FORWARDED_FOR'); else if(getenv('HTTP_FORWARDED'))   $ipaddress = getenv('HTTP_FORWARDED'); else if(getenv('REMOTE_ADDR')) $ipaddress = getenv('REMOTE_ADDR'); else $ipaddress = 'UNKNOWN'; return $ipaddress; } Method to fetch countryname & city  $id=trim('122.177.145.202'); $result  = array('country'=>'', 'city'=>''); $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=...

Change in bootstrap datatable

How to change default sorting & disable sorting.   $('.dataTables-example').dataTable({ "order": [[ 7, "desc" ]], columnDefs: [   { orderable: false, "targets": -1 } ] }); Notes: 1.It will change default sorting to 7 column 2. Disable sorting form last column.

PHP XML handling

songs.xml <songs>     <song dateplayed="2011-07-24 19:40:26">         <title>I left my heart on Europa</title>         <artist>Ship of Nomads</artist>     </song>     <song dateplayed="2011-07-24 19:27:42">         <title>Oh Ganymede</title>         <artist>Beefachanga</artist>     </song>     <song dateplayed="2011-07-24 19:23:50">         <title>Kallichore</title>         <artist>Jewitt K. Sheppard</artist>     </song> </songs> eg <?php     $mysongs = simplexml_load_file('songs.xml');     echo "<ul id="songlist">n";     foreach ($mysongs as $songinfo):         $title=$songinfo->title;       ...