Skip to content

Instantly share code, notes, and snippets.

@atishgoswami
atishgoswami / Cakephp::breadCrumbs
Last active December 17, 2015 00:29
Cakephp Dynamic BreadCrumbs
<?php
$action = $this->params->action;
if ($this->params->admin) {
$action = str_replace('admin_', '', $action);
}
if ($action == 'index') {
$options = array('class' => 'current');
} else {
@atishgoswami
atishgoswami / Cakephp::.gitignore
Created May 5, 2013 18:22
Git Ignore file for cakephp projects
# CakePHP
/app/tmp/*
/app/Config/database.php
/app/Config/core.php
!empty
/plugins
/vendors
/app/webroot/coverage/*
/tmp/*
/app/Plugin/*
@atishgoswami
atishgoswami / cakephp::error class helper
Created May 5, 2013 18:25
Helper for Error class for form fields
/**
* applyClass method
*
* @param string $feildname form feild name
*
* @return boolean true if isFieldError satisfies else false
*/
public function applyClass($feildname)
{
@atishgoswami
atishgoswami / Cakephp:: SQL Condition
Created May 7, 2013 12:24
Condition for comparing only the day and month of a repeating holiday date
if (!$conditionState) {
$condition = array(
'OR' => array(
array(
'Holiday.date' => array(
$dates['start'], $dates['end'],
)
),
array(
'EXTRACT(MONTH FROM Holiday.date)' => date('m', strtotime($dates['start'])),
@atishgoswami
atishgoswami / Cakephp:::callback false
Last active December 17, 2015 01:59
Disable callbacks on save mainly focusing on not calling aftersave
saveField(string $fieldName, string $fieldValue, array $params = array())
$params array can have any of the following available options as keys:
validate Set to true/false to enable disable validation.
callbacks Set to false to disable callbacks. Using ‘before’ or ‘after’ will enable only those callbacks.
$leaveSettings['WeekDiff'] =
(int)floor(date_diff(new DateTime($leaveSettings['sessionStartDate']), new DateTime($presentDay))->days/7);
@atishgoswami
atishgoswami / Cakphp::SQL Queries
Last active December 17, 2015 02:19
SQL Conditional Field Query
<?php
$conditionalField
= '(IF( User.joined_date IS NOT NULL,
DATE_FORMAT(User.joined_date, "%d-%m"),
DATE_FORMAT(User.created, "%d-%m")))';
$conditionalField2
= '(IF( User.joined_date IS NOT NULL,
DATE_FORMAT(User.joined_date, "%Y"),
DATE_FORMAT(User.created, "%Y")))';
$this->User->recursive = -1;
<script>
if (/*@cc_on!@*/false) {
var headHTML = document.getElementsByTagName('head')[0].innerHTML;
headHTML += '<link type="text/css" rel="stylesheet" href="assets/ie.css">';
document.getElementsByTagName('head')[0].innerHTML = headHTML;
}
</script>
@atishgoswami
atishgoswami / git.sh
Last active December 18, 2015 16:29
Git Export Diff files Between two commits
git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD~1 HEAD | xargs tar -rf ~/exports/export.tar
@atishgoswami
atishgoswami / concat.js
Last active December 18, 2015 19:09
Fix sahi to work with firefox 21
//Open sahi/htdocs/spr/concat.js
//and look for:
Sahi.prototype._isFF2 = function () {return /Firefox\/2|Iceweasel\/2|Shiretoko\/2/.test(this.navigator.userAgent);};
Sahi.prototype._isFF3 = function () {return /Firefox\/3|Iceweasel\/3|Shiretoko\/3/.test(this.navigator.userAgent);};
Sahi.prototype._isFF4 = function () {return /Firefox\/4|Iceweasel\/4|Shiretoko\/4/.test(this.navigator.userAgent);};
Sahi.prototype._isFF5 = function () {return /Firefox\/5|Iceweasel\/5|Shiretoko\/5/.test(this.navigator.userAgent);};
//and replace it with
@atishgoswami
atishgoswami / ubuntu.sh
Created July 3, 2013 09:58
Apache setup Userdir
//run command
sudo a2enmod userdir
//open file
sudo nano /etc/apache2/mods-available/php5.conf
//change
<IfModule mod_userdir.c>