OMG OMG OMG! WordPress 2.7 is almost here. Here is a long list of the changes that are going to be in the latest release. I have been a huge wordpress fan for some years now. Its always treated me well. Its treated me so well that I have decided to move my main website, notPopular.com, to the wordpress platform for content management. I’m really nervous though, I have done a lot of custom work on the notpop install of wordpress, and it isnt released yet. I hope that my plugins and custom code doesnt break to badly. I will have a full review of wordpress 2.7 once it is released later this week.
Author: Josh Highland
I love my friends
[vimeo]http://vimeo.com/2360119[/vimeo]
All of these guys are really good friends of mine. I love my friends, I love music, I love the redlands music scene.
How I do layouts and views in CodeIgniter
I have been a loyal fan of the kick-ass php framework, codeIgniter, for some time now. A while back I made a post on how to improve the view handling of codeIgniter. I would like to retract that post. Through the comments on that post I found out about an undocumented parameter (as of version 1.7, it has been documented) that allows view to be rendered into a variable. This changes everything, and totally negates any of the complaint I had about how CI handles layouts and views.
Below is an example of live code I have running at loudsongs.com. It shows how I have been able to take advantage of of this powerful third parameter that stops CI from rendering a view to the screen when loading it.
Inside of my controller
function index()
{
$base_url = base_url();
//what the nav needs
$navigation_data['navTab'] = "home";
//basic info for the header
$layout_data['pageTitle'] = "LoudSon.gs";
$layout_data['meta_description'] = "Under Ground Lyrics, hardcore, metal, emo, rock";
$layout_data['meta_keywords'] = "lyrics,song,songs,words,hardore,metal,emo,rock";
$layout_data['meta_url'] = "$base_url";
$layout_data['meta_classification'] = "home";
$layout_data['searchInput'] = "";
$layout_data['searchOptions'] = "";
$this->load->model('search');
$lastest_albums = $this->search->last_n_albumsAdded(10);
$popular_songs = $this->search->popular_n_songs(10);
//get the featured Albums
$featuredAlbums = $this->search->getFeaturedAlbums();
$body_data['featured'] = $featuredAlbums;
$body_data['newest'] = $lastest_albums;
$body_data['popular'] = $popular_songs;
//load the content variables
$layout_data['content_navigation'] = $this->load->view('navigation', $navigation_data, true);
$layout_data['content_body'] = $this->load->view('home/homePage', $body_data, true);
$this->load->view('layouts/main', $layout_data);
}
/views/navigation.php
<div id="header">
<h1 title="Loud Songs Logo">LoudSongs search - hard to find obscure lyrics</h1>
<ul title="navigation">
<li <? if($navTab == "about"){echo " id=\"active\"";}?>><a href="<?= base_url(); ?>about" title="About Page">About</a></li>
<li <? if($navTab == "add"){echo " id=\"active\"";}?>><a href="<?= base_url(); ?>add" title="Add Lyrics">Add Lyrics</a></li>
<li <? if($navTab == "home"){echo " id=\"active\"";}?>><a href="<?= base_url(); ?>" title="Home Page">Home</a></li>
</ul>
</div>
/views/home/homePage.php
<div>
Thanks for visiting LoudSongs
<br/>
We are trying to build a maintain a collection of punk rock, hardcore, emo, metal and other lyrics.
This website is free and open to all.
Please help us by <a href="http://www.LoudSon.gs/add">contributing to the collection</a>.
</div>
<div>
<? $this->load->view('home/featuredAlbums'); ?>
</div>
<div class="middle_col_split">
<? $this->load->view('home/recentlyAdded'); ?>
</div>
<div class="middle_col_split">
<? $this->load->view('home/mostPopularSongs'); ?>
</div>
/views/layouts/main.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=us-ascii">
<meta name="description" content="<?= $meta_description ?>">
<meta name="keywords" content="<?= $meta_keywords ?>">
<meta http-equiv="expires" content="0" />
<meta name="classification" content="<?= $meta_classification ?>" />
<meta name="Robots" content="index,follow">
<meta name="revisit-after" content="2 Days">
<meta name="language" content="en-us">
<link href="<?= base_url() ?>includes/styles/lyrics.css" rel="stylesheet" type="text/css" media="screen" title="default">
<script language="javascript" type="text/javascript" src="<?= base_url() ?>includes/scripts/jquery-1.2.6.min.js"></script>
<title><?= $pageTitle ?></title>
</head>
<body id="home">
<div id="nav">
<?= $content_navigation; ?>
</div>
<div id="middle_column">
<?= $content_body ?>
</div>
</body>
</html>
wow, ok, so that might be a lot to digest. The bottom line is this, CI doesnt have “layouts” like other frameworks, so you have to become creative and use a view AS a layout by using the mythical 3rd parameter when loading a view. We load data into the navigation view and store all of that into the $layout_data array, then we load a view named homePage and pass data into it, and stor it into the $layout_data array. When we are done loading all of the views into the array, we pass that array into another view. This view acts as our layout. easy as that! check it out below:
//load the content variables
$layout_data['content_navigation'] = $this->load->view('navigation', $navigation_data, true);
$layout_data['content_body'] = $this->load->view('home/homePage', $body_data, true);
$this->load->view('layouts/main', $layout_data);
I hope this helps someone understand how codeigniter does have layout and view functionality, you just have to structure it that way in your code.
post some comments if you need more clarification.
Highland’s Island
I love halloween. Halloween is my favorite. This year was extra special because my costume was part of a group. I have done halloween costumes with my former band, and with xFLORIDAx in the past, but this year my wife, Amy got involved.
Together we went as the cast of “Giligan’s Island”. I was gilligan, florida was the skipper and amy was mary ann.
We all wet to a party and had a great time there. I was actually suprised by the general lack of knowledge about Gilligan’s Island, but then again I am a geek with tons of usless knowledge in my head.
If you want to see more party pictures, please check out the Halloween 2008 Photo Set on flickr
LoudSon.gs : i <3 lyrics & code
LoudSon.gs is a website that I recently threw together in my attempt to tighten my strangle hold on teh interwebz (by the way, I’m losing)
LoudSon.gs is a lyrics website that focuses on hard to find album artwork and lyrics, mostly for punk, hardcore and emo bands, but the door is open for all types of music.
On the technical site, the site is built using PHP, MySQL, and is the first site that I have built using the codeIgniter framework. There is also some code integration with amazon for the album art, along with some other code wizardry.
But isn’t the internet full of lyric sites already?
Yeah, it is, but none of them specialize in the kind of music that speaks to me, so I built one.
The project started out as something personal for myself in 2004, then became part of notpopular.com in 2005. The original version lived for years at notPopular.com/lyrics, and was build out of some really bad php code and used a really sketch database. Instead of taking it down, I allow it to live on, but all new additions get added to LoudSon.gs.
I also decided to do some different things with this site. In an attempt to make the domain name a bit more memorable, I bought a non .com domain, sort of like del.icio.us. For easy, and for n00bz, you can also get to the site from LoudSongs.com. I also used some SES (search engine safe) URLS. The CodeIgniter framwork made that really easy to do.
Overall, this was probably one if the funnest projects I have worked on in a while. It’s a real labor of love on my part. The site takes time every day to maintain, the only way I will ever mak money from the site is throught the google ads.
Music is a huge part of my life. You can see the “about section” of LoudSon.gs to read more about that. LoudSon.gs sums up a lot about me, code, the internet and music.