Need to use session data in your model?
CakeSession::read('Auth.User.field');
Need to use session data in your model?
CakeSession::read('Auth.User.field');
This issue plagued me for way longer than it should. Due to lack of documentation online I figured it would be best to represent it here.
I kept getting Black-holed. The most common answer I found online was to disable security altogether. (Seriously, don't do that). Rather, the correct answer via consensus in the #CakePHP IRC, as well as multiple other hidden forum posts was to disable it on a per hidden field basis.
Easy answer. Make this:
<?
echo $this->Form->input('w', array('type' => 'hidden'));
<?
echo $this->Form->input('w', array('type' => 'hidden', 'security => false));
<? $this->Form->unlockField('Purchase.x');
For a few months, every time I pushed a commit I would play a sound clip. (Specifically Push It by Salt-n-Pepa) This was just for kicks, but would take a few seconds to open my Spotify account and actually find/play the clip.
Recently I found a way to add it to my post-commit hook in git.
Open .git and navigate to the folder called "hooks". Copy the post-commit.sample and save it as post-commit.
Enter the following command:
afplay "/path/to/file/Pushit.m4a"
NOTE: This only works on mac.
This comes from a post here: http://www.joestrong.co.uk/blog/css-tip-how-to-match-column-heights-in-css/
A huge problem (come on CSS devs, we're ready for smarter code! We shouldn't needs jquery or LESS to fix your crap!) is matching a heights to a sibling div.
eg: http://jsfiddle.net/9d5f2/
Notice how in the preview it shows the yellow as much shorter than the pink? What if we wanted the sibling divs to match in height? Well we could use jQuery, or some other javascript library to finagle the height to the same as it's sibling, but that just isn't necessary. Not only does it require you to likely use a library such as jQuery (including ANOTHER http request) but it also has to process the action.
SOLUTION:
Simply add the following to the short column's css:
padding-bottom: 30000px;
margin-bottom: -30000px;
I lost this article once, and I shall never do that again. This originates from here.
This is basically all you need to know:
div.container {
border: 1px solid #000000;
overflow: hidden;
width: 100%;
}
div.left {
width: 45%;
float: left;
}
div.right {
width: 45%;
float: right;
}
This goes out to all the theme developers out there. EVERY SINGLE DESIGNER NEEDS TO IMPLEMENT THIS NOW
Featured images are great, unless the user doesn't add them. This solution will allow your template users to have engaging experience with your templates. If you are a template designer, it means more money for you.
Article can be read here: http://www.wpbeginner.com/wp-themes/how-to-set-a-default-fallback-image-for-wordpress-post-thumbnails/
To utilize the tricks in this post, you have to enable the post thumbnails in your WordPress theme.
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>">
<?php } ?>
This is the very basic example. You can obviously expand on it with thumbnail sizes, class and much more.
<?
//function to call first uploaded image in functions file
function main_image() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment
&post_mime_type=image&order=desc');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', true);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$main=wp_get_attachment_url($num);
$template=get_template_directory();
$the_title=get_the_title();
print "<img src='$main' alt='$the_title' class='frame' />";
endif;
}
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) {
echo get_the_post_thumbnail($post->ID);
} else {
echo main_image();
} ?>
Explanation: First we create a function that gets the first image attachment for each post. In our theme file code, we check if the post has a thumbnail. If the thumbnail exist, then we display the thumbnail, and if it does not exist, then we display the fallback.
Source: Snipplr
This is just the start. You can get creative with the fallback images for WordPress post thumbnails. You can combine the two techniques mentioned above, create branded images for each category, and much more.
If you are a theme developer, then make sure you have this in your themes.
Are you like me in that anything regex makes your skin crawl? Do you feel like throwing up when you see something like: /\[BLOG\=\[(.*?)\]\](.*?)\[\/BLOG\]/U
I do. So here's a few resources to hopefully help you sort things out:
Regex Generator: http://txt2re.com/
Regex CheatSheat: http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
Hope this helps!
Skyler
This problem came up where I needed to remove a folder. Removing a folder is easy, only the PHP command rmdir() only removes the folder if it is empty. The PHP command unlink() is only for files.
So how do I recursively delete a folder that might not be empty? Here is a function for you:
<?
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
<?
rrmdir('folderName');