PinoyTech.org

Code Completion with Codeigniter using Netbeans

Posted by teejay on June 18, 2009

Most programmers are lazy. If you're like me, you're lazy too. That's why I was so happy about using code completion with CodeIgniter using the Netbeans IDE.

Here's how you'd set it up

/**
 * MY_Model
 *
 * @property CI_DB_active_record $db
 */
class MY_Model extends Model {

With the following code, you can now access the Active Record method and properties using Netbeans codecompletion. You'll just type in $this-> and a list of property shows up including $this->db.

Here's a little explanation.

CI_CD_active_record is the actual class we are accessing. the variable $db is the property you'll be using in the model (in this case).

Take note that you can do this also in the Controller. I highly suggest using a MY_Controller so that you just apply it once.

Another thing is that you'd have to set up a project in Netbeans.

Oh yeah, I have to thank the softbas.

Categories: How To, Web Development

Tags: codeigniter, php

Firefox 3.5 Font Face Support

Posted by teejay on June 18, 2009

I've just installed the Beta Version of Firefox 3.5. I can honestly say that I packs a lot of improvement.

I am mostly talking about the CSS support that has gone into it.

I've been experimenting a while back about using download-able fonts in web pages. Right now, my header uses a very uncommon font which I downloaded from fontsquirrel.

The thing is, it's so easy to implement. Here's how:

@font-face {
    font-family: Aller;
    src: url("http://pinoytech.org/application/views/templates/minimal/font/Aller_Lt.ttf");
    font-style: normal;
    font-weight: normal;
}

With the following code you can do this in your style sheets.


body {
 font-family: Aller, Arial, Sans-serif;
 text-rendering: optimizeLegibility;
}

This just one of the many exciting things in Firefox 3.5.

This is already supported by the Safari 4

Note: If you upgrade to Firefox 3.5, some plugins might not work.

Categories: How To, Web Development

Tags: css

CodeIgniter: Route Everything, except these Controllers

Posted by teejay on June 11, 2009

There was a recent post on the codeigniter forums trying to get urls like these:

http://yoursite.com/your-slug

This problem could have been easily resolved using this route:

$rout['(:any)'] = 'articles/$1';

In this route, all characters after the domain will be passed to the controller, 'article'.

However, the problem was he also had some controllers that he didn't want to use the route for. A quick fix for the route was to use a 'simple' regex using negative lookahead

$route['^(?!controller|controller|controller)\S*'] = "article/$1";

Categories: Web Development

Tags: codeigniter, php

Adding an Icon to External links using Mootools

Posted by teejay on June 4, 2009

Some usability websites have said that adding a certain image or indicator for links linking outside your domain should be done. I really don't know but as part of regularly modifying this blog, I decided to add this as well.

Learning jQuery posted a script for this using jQuery. David Walsh also posted something similar. However, what I did was to push it further and write up class for the same purpose.

var external = new Class({
 initialize: function(links) {
  this.links = $$(links);
  this.attach();
 },

 attach: function() {
  this.links.each(function(link){
   if (!link.get('href').contains(window.location.host)) {
    link.addClass('external');
   }
  });
 }
});

Usage

    new external('a');    

CSS declaration

.external {
    background: url('http://pinoytech.org/application/views/templates/minimal/images/external.png') 100% 60% no-repeat;
    padding:  0 15px 0 0;
}

Categories: How To, Web Development

Tags: javascript, mootools

Automatically Get the Base URL for CodeIgniter

Posted by teejay on June 3, 2009

Everytime, we set up or move a Codeigniter site, we have to make sure that the base_url in the config file is correctly set.

Someone recently asked in the CodeIgniter forums about this and we came up with something like this

$config['base_url']    = ((empty($_SERVER['HTTPS']) OR $_SERVER['HTTPS'] === 'off') 
                                     ? 'http' : 'https').'
                                     ://' . $_SERVER['HTTP_HOST'] . '/';

This snippet of code works but unfortunately doesn't when you've set up CodeIgniter in a subdirectory.

Categories: How To, Web Development

Tags: codeigniter, php

CodeIgniter and The HTML Base Tag

Posted by teejay on June 2, 2009

You learn something 'new' everyday. This isn't exactly new but it's new to me.

Today, at the CodeIgniter forums, xwero posted an alternative to doing the following:

    <?php echo base_url() . 'css/styles.css ?>

The alternative was to use the HTML base tag, which was frankly the first time I've heard of such a tag.

The HTML Base Tag description is, &lquo;The <base> tag specifies a default address or a default target for all links on a page.&rquo;

As posted in the forums, a very useful usage for this is to use it as a base for css and the images folders.

<base href="<?php echo base_url() ?>">
<link type="text/css" rel="stylesheet" href="css/styles.css">

Categories: How To, Web Development

Tags: codeigniter, php

Learning Mootools

Posted by teejay on June 1, 2009

When I needed to finish your work as soon as possible, jQuery was there for me, especially with my 'very' limited javascript knowledge :)

However, Mootools has always been "the javascript framework I wanted to learn". And recently I've been trying to learn more about it. Trying it out for this site was the most logical for me to learn faster and after a long long day, I tried successfully to convert the 'easy' javascript implementations on my blog to use Mootools instead of jQuery.

Seriously, it was fun. Anyway, here's the resulting Mootools class. The class is very basic. It just allows the 'Search' text on this blog's Search input to disappear when you focus on it and returns it when you lose focus.

var search = new Class({
    initialize: function(input) {
        this.input = $(input);
        this.default = this.input.get('value');
        this.attach();
    },
    attach: function() {
        this.input.addEvent('focus', function(event){
            event.preventDefault();
            console.log('you clicked on me!!');
            this.input.set('value', '');
        }.bind(this));
        this.input.addEvent('blur', function(event) {
            event.preventDefault();
            console.log('please click on me now!!');
            this.input.set('value', this.default);
        }.bind(this));
    }
});

It's easy to use. Next time I need something with this functionality, I'd just type include the class and type in:

window.addEvent('domready', function(){
        new search('searchtext');
});

Not the neatest implementation you could probably find but I think I'll get there.

Categories: Site News, Web Development

Tags: javascript, mootools

Iconza: Free customizable website Icons

Posted by teejay on May 28, 2009

Icons are visual representation of links to different functions of the web applications.

Quite often, we web developers need icons for create interfaces for clients. Especially on the administration part or back end part of web applications. We then find ourselves on this page or this one.

I have now discovered a different route.

Iconza lets you create customizable icons for your web applications. Available customizations are the color, background color and the size.

One drawback though is that they aren't as good as the wefunction icons.

Categories: Cool Links

Tags: icons