Saturday 28 January 2012

How can Direct Import model in .ctp file without controller in cake php


How can Direct Import model in .ctp file without controller in cake php

 App::import('Model','ModelName');
                    $this->ModelName=new ModelName();
                    $active=$this->ModelName->functionName($parameters);

Friday 27 January 2012

Running a CakePHP SQL query manually

How to run manually SQL database query in CakePHP

$qry="SELECT * FROM table name";
 $result=$this->model->query($qry); //result in array


Thursday 5 January 2012

downloads function in cake php

function admin_downloadForms($filename=null) {
        //echo $filename=base64_decode($filename);
      
     $filename = WWW_ROOT . "uploads/uploadform/".$filename;
                if (file_exists($filename)) {
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                header("Cache-Control: private", false);
                header("Content-Type: application/force-download");
                header("Content-Type: application/pdf");
                header("Content-Description: File Transfer");
                header("Content-Disposition: attachment; filename=" . basename($filename) . ";");
                header("Content-Transfer-Encoding: binary");
                header("Content-Length: " . filesize($filename));
                readfile($filename) or die('Errors');
                exit(0);
                }
                $this->autoRender=false;
    }