Subversion hosting, CVS hosting, Trac hosting, Bugzilla hosting and software collaboration Providing hosted Subversion, CVS, Trac and Bugzilla repositories
 

March 7, 2008

Basic Views In CodeIgniter

Filed under: Software Development — Tags: , , , , — Greg Larkin @ 3:24 pm

Hi everyone,

A while back, I hooked up my CodeIgniter sample application to a MySQL database. That was easy, and now I’ll show how to move your presentation code into separate view files, instead of echo’ing HTML from inside a controller file.

According to the CodeIgniter manual, views are stored in the /views (hmm, that makes sense!) directory of your application, and they can be divided up across functional areas with subdirectories. Since it’s possible to create page snippets and load them in sequence, you might have a directory structure like this:

/views
  /global
    /layout
      /header.php
      /footer.php
  /navigation
      /left_side.php
      /bottom_links.php
  /user
    /add.php
    /edit.php
    /delete.php
    ...
  /group
    /add.php
    /edit.php
    /delete.php
    ...
  /...
  /...

Then when you want to render a particular page, say the “add user” page of your web app’s administrative interface, the code would look like this:

$this->load->view(‘global/layout/header.php’);
$this->load->view(‘global/navigation/left_side.php’);
$this->load->view(‘user/add.php’);
$this->load->view(‘global/navigation/bottom_links.php’);
$this->load->view(‘global/layout/footer.php’);

I haven’t gotten that complex yet, but I did move the code to display my user count into a view and set the value in the controller like so:

function count_users()
{
        $numUsers = $this->user->count_users();
        $data = array(‘num_users’ => $numUsers);
        $this->load->view(‘user/showcount’, $data);
}

The file /views/user/showcount.php is pretty simple:

<html>
<head><title>Welcome to the User Area!</title></head>
<body>
This page is rendered by the file: <?php echo __FILE__; ?>
<p>There are <?php echo $num_users; ?> users defined in the database.
<p><?php echo anchor(’user’, ‘Go back’); ?>
</body>
</html>

Ok, this all seems to be pretty easy. Of course, there’s a bunch more functionality in the CodeIgniter framework, but I think what I’ll do for my next post is shift gears and go through the same basic exercises using CakePHP, Prado, and the Zend Framework.

It will be interesting to see if there’s any similarity to the way the classic “Hello, world.” program varies in complexity based on implementation language!

Keep in touch,
Greg


Share this with others: del.icio.us:Basic Views In CodeIgniter  digg:Basic Views In CodeIgniter  newsvine:Basic Views In CodeIgniter  furl:Basic Views In CodeIgniter  reddit:Basic Views In CodeIgniter  fark:Basic Views In CodeIgniter  blogmarks:Basic Views In CodeIgniter  Y!:Basic Views In CodeIgniter  magnolia:Basic Views In CodeIgniter

March 6, 2008

FreeBSD Port For CodeIgniter Upgraded to 1.6.1

Filed under: Software Development — Tags: , , , , , — Greg Larkin @ 7:01 pm

Hi everyone,

I’ve submitted some new FreeBSD port upgrades over the past week, including new support for CodeIgniter 1.6.1. In addition to the version bump of the upstream distribution, I also added some new bits to allow customization of certain CI files. The port is also careful to avoid removing those modified files when a new port upgrade comes along.

The reference for how to handle user-configurable files installed as part of a port can be found in the excellent FreeBSD Porter’s Handbook in the Configuration Files section.

In the new CodeIgniter port, the following user-configurable files are installed:

<INSTALL_DIR>/index.php
<INSTALL_DIR>/index.php.sample
<INSTALL_DIR>/system/application/config/autoload.php
<INSTALL_DIR>/system/application/config/autoload.php.sample
<INSTALL_DIR>/system/application/config/config.php
<INSTALL_DIR>/system/application/config/config.php.sample
<INSTALL_DIR>/system/application/config/database.php
<INSTALL_DIR>/system/application/config/database.php.sample
<INSTALL_DIR>/system/application/config/hooks.php
<INSTALL_DIR>/system/application/config/hooks.php.sample
<INSTALL_DIR>/system/application/config/mimes.php
<INSTALL_DIR>/system/application/config/mimes.php.sample
<INSTALL_DIR>/system/application/config/routes.php
<INSTALL_DIR>/system/application/config/routes.php.sample
<INSTALL_DIR>/system/application/config/smileys.php
<INSTALL_DIR>/system/application/config/smileys.php.sample
<INSTALL_DIR>/system/application/config/user_agents.php
<INSTALL_DIR>/system/application/config/user_agents.php.sample

What this does is install a reference copy of each file (*.sample) that is not expected to be edited by the user. The actual file that CodeIgniter uses to render pages (no .sample suffix) is user-configurable as needed.

Then some crazy-looking shell code in the pkg-plist file makes sure that any edited files are not removed if the port is deinstalled or upgraded (reformatted for readability):

@unexec if cmp -s %D/%%WWWDIR%%/%%CI_CONF_DIR%%/autoload.php.sample \

    %D/%%WWWDIR%/%%CI_CONF_DIR%%/autoload.php; then \

    rm -f %D/%%WWWDIR%%/%%CI_CONF_DIR%%/autoload.php; else \

    %%ECHO_MSG%% "===> Customized %D/%%WWWDIR%%/%%CI_CONF_DIR%%/autoload.php \

    has not been removed"; fi

%%WWWDIR%%/%%CI_CONF_DIR%%/autoload.php.sample

@exec if [ ! -f %D/%%WWWDIR%%/%%CI_CONF_DIR%%/autoload.php ]; then \

    cp -p %D/%F %B/autoload.php; fi

This concept needs to be implemented in several of the other ports that I maintain, including CakePHP and Prado. If anyone has a list of files that are user-configurable in each of those frameworks, please send it along!

Keep in touch,
Greg


Share this with others: del.icio.us:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  digg:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  newsvine:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  furl:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  reddit:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  fark:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  blogmarks:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  Y!:FreeBSD Port For CodeIgniter Upgraded to 1.6.1  magnolia:FreeBSD Port For CodeIgniter Upgraded to 1.6.1

February 15, 2008

CodeIgniter 1.6.1 Is Released

Filed under: Software Development — Tags: , , , , — Greg Larkin @ 4:31 pm

Hi everyone,

I just saw that CodeIgniter 1.6.1 has been released. I guess that means I’d better get on the stick and upgrade the FreeBSD CodeIgniter port! Once I do that, I’ll upgrade my PHP Framework VM with the new version of the port and continue on with the experimentation.

Keep in touch,
Greg


Share this with others: del.icio.us:CodeIgniter 1.6.1 Is Released  digg:CodeIgniter 1.6.1 Is Released  newsvine:CodeIgniter 1.6.1 Is Released  furl:CodeIgniter 1.6.1 Is Released  reddit:CodeIgniter 1.6.1 Is Released  fark:CodeIgniter 1.6.1 Is Released  blogmarks:CodeIgniter 1.6.1 Is Released  Y!:CodeIgniter 1.6.1 Is Released  magnolia:CodeIgniter 1.6.1 Is Released

February 6, 2008

RSS Feed for FreeBSD /usr/ports/UPDATING

Filed under: Operating Systems — Tags: , — Greg Larkin @ 10:44 am

Hi everyone,

Since I’ve transitioned to FreeBSD, one thing I haven’t done regularly is keep track of the /usr/ports/UPDATING file. This file contains important information about incompatible changes to ports that could cause a port upgrade to break or yield unexpected results. Therefore, it’s important to check it before running a wholesale upgrade on a production server.

I’ve been using Awasu as my desktop RSS reader, and every time I find something I want to keep track of without having to remember to do so, I look for an RSS feed. The contents of the UPDATING file seem a natural fit for delivery as an RSS feed, but a few Google searches yielded no results.

Finally, I went straight to the freebsd-ports mailing list archive, and simply searched for “rss”. Lo and behold, Alex Kapranoff set up a feed back in 2005: http://lists.freebsd.org/mailman/htdig/freebsd-ports/2005-June/024285.html

The feed URL is http://kapranoff.ru/~kappa/files/ports.UPDATING.rss20.xml, for anyone who’s interested. Thanks Alex!

Keep in touch,
Greg


Share this with others: del.icio.us:RSS Feed for FreeBSD /usr/ports/UPDATING  digg:RSS Feed for FreeBSD /usr/ports/UPDATING  newsvine:RSS Feed for FreeBSD /usr/ports/UPDATING  furl:RSS Feed for FreeBSD /usr/ports/UPDATING  reddit:RSS Feed for FreeBSD /usr/ports/UPDATING  fark:RSS Feed for FreeBSD /usr/ports/UPDATING  blogmarks:RSS Feed for FreeBSD /usr/ports/UPDATING  Y!:RSS Feed for FreeBSD /usr/ports/UPDATING  magnolia:RSS Feed for FreeBSD /usr/ports/UPDATING

February 1, 2008

Installing PHP Frameworks with the FreeBSD Ports Tree

Filed under: Software Development — Tags: , , , , — Greg Larkin @ 11:21 am

Hi everyone,

Ok, let’s proceed to install the various PHP frameworks that we’ll use to create a sample application.

As I mentioned in a previous post, the basic command for installing any port in the tree is:

cd /usr/ports/<category>/<appname> && make install clean

Let’s start with the CakePHP framework:

cd /usr/ports/www/cakephp && make install clean

After typing that command, you should see this on the screen:

FreeBSD Port Installation Options

Hmm, what is that screen for? The FreeBSD ports collection has a robust infrastructure for configuring software applications prior to installation. In this case, CakePHP works with multiple different database backends, so the port writer (i.e. me) decided to provide options so the prerequisite bits are installed before the port proper.

Looking at the options provided here, the first one named “PROD” determines the way that the Apache web server is configured for CakePHP. If this is a production server, this option should be selected so navigating to “http://<servername>/” displays the CakePHP welcome page. Since I am installing multiple frameworks on the same machine, I’ll leave this option unchecked. That way, each framework welcome page will be found at “http://<servername>/<frameworkname>/”.

I plan to use MySQL as a database backend, so the following screenshot shows the MYSQL option selected. The dialog box is navigated with the tab and arrow keys on your keyboard, and the spacebar toggles the option selections:

FreeBSD Port MySQL Option

Tab to the OK button and hit Enter, and the port build starts. Here is the full transcript of the process:

CakePHP Port Build Transcript

Notice that by selecting the MYSQL option prior to installation, the port build fetched and built the MySQL client library and the PHP MySQL module, as well as some other packages:

mysql-client-5.0.51
php5-pcre-5.2.5_1
php5-pdo-5.2.5_1
php5-pdo_mysql-5.2.5_1
php5-session-5.2.5_1

This helps us get a working PHP installation that supports CakePHP out of the box.

Now, it’s the moment of truth - does the CakePHP default page display correctly? In order to load the page on your host machine, find the VM’s IP address with the following command:

/sbin/ifconfig -a | grep -w inet | grep -v 127.0.0.1 | awk '{ print $2 }'

That gives me 192.168.95.128, so here’s the URL where I should find the CakePHP default page: http://192.168.95.128/cakephp/. The address will likely be different for you.

This looks good!

CakePHP Default Page

Now as an exercise for the reader, try installing the rest of the frameworks and make sure that they display their welcome pages:

CodeIgniter
PRADO
Zend Framework

If you have any trouble, write in with comments and feedback.

Keep in touch,
Greg


Share this with others: del.icio.us:Installing PHP Frameworks with the FreeBSD Ports Tree  digg:Installing PHP Frameworks with the FreeBSD Ports Tree  newsvine:Installing PHP Frameworks with the FreeBSD Ports Tree  furl:Installing PHP Frameworks with the FreeBSD Ports Tree  reddit:Installing PHP Frameworks with the FreeBSD Ports Tree  fark:Installing PHP Frameworks with the FreeBSD Ports Tree  blogmarks:Installing PHP Frameworks with the FreeBSD Ports Tree  Y!:Installing PHP Frameworks with the FreeBSD Ports Tree  magnolia:Installing PHP Frameworks with the FreeBSD Ports Tree

Powered by WordPress