Skip to content

Instantly share code, notes, and snippets.

View jawinn's full-sized avatar

Josh Winn jawinn

View GitHub Profile
@jawinn
jawinn / loadModelSlug.php
Last active December 31, 2015 16:09
loadModelSlug, Yii - from clean URL tutorial
public function actionView($slug)
{
$this->render('view',array(
'model'=>$this->loadModelSlug($slug),
));
}
public function loadModelSlug($slug)
{
$model = Product::model()->findByAttributes(array('slug'=>$slug));
@jawinn
jawinn / urlManager_Example.php
Created December 17, 2013 20:37
Yii urlManager Example
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'rules'=>array(
// custom rules go first
'product/<slug:[a-zA-Z0-9-]+>/'=>'product/view',
// default controller url setup
'<controller:w+>/<id:d+>'=>'<controller>/view',
'<controller:w+>/<action:w+>/<id:d+>'=>'<controller>/<action>',
'<controller:w+>/<action:w+>'=>'<controller>/<action>',
@jawinn
jawinn / urlManagerRules.php
Created December 17, 2013 20:39
urlManager Rules
'about' => array('site/page', 'defaultParams' => array('view' => 'about')),
'example' => array('site/page', 'defaultParams' => array('view' => 'example')),
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
@jawinn
jawinn / CreateWordpressUser.php
Last active December 16, 2023 21:58
Create WordPress Admin User from PHP
<?php
// ADD NEW ADMIN USER TO WORDPRESS
// ----------------------------------
// Put this file in your Wordpress root directory and run it from your browser.
// Delete it when you're done.
require_once('wp-blog-header.php');
require_once('wp-includes/registration.php');
// ----------------------------------------------------
@jawinn
jawinn / CodeIgniterCheckUsername.php
Created December 17, 2013 20:52
CodeIgniter - Check username exists
//---------------------------------
// EMAIL EXISTS (true or false)
//---------------------------------
private function email_exists($email)
{
$this->db->where('email', $email);
$query = $this->db->get('users');
if( $query->num_rows() > 0 ){ return TRUE; } else { return FALSE; }
}
@jawinn
jawinn / checkUsername.js
Created December 17, 2013 20:54
CodeIgniter - check username exists, JS validation plugin
rules: {
email1: {
required: true,
email: true,
remote: {
url: "/registration/register_email_exists",
type: "post",
data: {
email: function(){ return $("#email").val(); }
}
@jawinn
jawinn / snazzy-layout-3.php
Created December 17, 2013 21:03
Snazzy Layout 3 (old)
<div class="sz_cont <?php echo ( ( $post->post_type=='page' ) ? "sz_page" : "sz_post" ) ?>" >
<a class="sz_title" href="<?php echo $url ?>"><?php echo $title ?></a>
<?php // GET THE FIRST IMAGE ATTACHMENT ?>
<?php
$args = array(
'numberposts' => 1,
'order'=> 'ASC',
@jawinn
jawinn / htmltag.html
Created December 17, 2013 21:07
HTML Head Conditional Classes
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8 ie7" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9 ie8" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en"> <!--<![endif]-->
@jawinn
jawinn / old_IE_conditional.js
Created December 17, 2013 21:08
Different jQuery to old version of IE
// Found this nice function on StackOverflow, which you don't necessarily need.
jQuery.fn.exists = function(){
return jQuery(this).length>0;
}
// Example jQuery Code
$(document).ready(function()
{
// Hover function which gives different javascript to older IE
$("table.inv-table .inv-link").hover(function(){