Category: CakePhp
condition in find function cakephp
How to get data on condition that start time only have current year data:
CakePHP cake bake command
step 1: set path to environment variable. like: C:\xampp\php;C:\xampp\htdocs\yourproject\lib\cake\console\; step 2: open command prompt and type cd C:\xampp\htdocs\yourproject\app and press enter. step 3: now type cake bake now you can see the options there. you can continue accordingly.
Convert array to object and object to array in PHP
convert array to object PHP $obj = json_decode (json_encode ($var), FALSE); where $var is an array. convert object to array PHP $arr = json_decode( json_encode($var), true); where $var is an object
How to use native php function in cakephp
//your core php code function __autoload($name) { require_once($name . ‘.php’); } //in cakephp you can use like this function my_autoloader($name) { require_once($name . ‘.php’); } spl_autoload_register(‘my_autoloader’);
How to store csv file to the database in cake php by coding
function admin_exceladd(){ if (!empty($this->data)) { if(is_uploaded_file($this->data[‘Webshop’][‘excelfile’][‘tmp_name’])){ move_uploaded_file($this->data[‘Webshop’][‘excelfile’][‘tmp_name’], ‘img/files/’.$this->data[‘Webshop’][‘excelfile’][‘name’]); $file = ‘img/files/’.$this->data[‘Webshop’][‘excelfile’][‘name’]; $handle = fopen($file, “r”); // read the 1st row as headings $header = fgetcsv($handle); // read each data row in the file $i = 0; // for the message…
Uploading files
CREATE TABLE my_files ( id INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(75) NOT NULL, type VARCHAR(255) NOT NULL, size INT(11) NOT NULL, data MEDIUMBLOB NOT NULL, created DATETIME, modified DATETIME, PRIMARY KEY (id) ); // app/models/my_file.php class MyFile extends AppModel {…