Keeping migrations simple and to the point coupled with descriptive identifiers has many benefits. Functionally, it is easy to see the progression of the application’s schema. Also, certain assumptions do not have to be made. In the example below, migration 5 removes an index for Churches. No previous migrations say that we specifically added it. Therefore, we can assume this logic is in migration 1. Of course, real world examples can immensely compound the situation and can increase time spent tracking down logic that needs to be altered or removed.
Examples based on the current available transformations:
001_create_churches.rb
002_create_members.rb
003_relate_members_to_churches.rb
004_add_column_email_to_members.rb
005_remove_index_denomination_from_churches.rb
... and so on ...
Posted in Rails | No Comments »
Coming from a procedural background, I naturally blend the responsibilities of Controllers with Models. After reading CodeIgniter 101: Models written by Jesse Terry, I noticed that the initialization of Models seems to fit best in Controllers.
< ?php
class Example_model extends Model
{
var $address = '';
var $name = '';
function Example_model() {
parent::Model();
}
}
We can now access the object’s member variables directly.
< ?php
class Example extends Controller
{
function Example() {
$this->load->model('Example_model');
}
function create() {
$this->load->model('Example_model');
$this->example_model->address = $this->input->post('address');
$this->example_model->name = $this->input->post('name');
$this->example_model->create();
}
}
Of course, this is primitive. If you have PHP5 available, incorporating “getter” and “setter” methods would be ideal as you could declare private member variables for added security and encapsulation.
Posted in CodeIgniter | No Comments »
I’ve found it easy to keep everything as close to the document root as possible. Since CodeIgniter is a front-controller-based MVC framework, everything is run through /index.php.
Below is an example of the contents of my typical application’s document root using CodeIgniter.
/css
/images
/javascript
/system
/.htaccess
/index.php
To access an image from a view, you can use an absolute path like the example below.
<img src="/images/foo.gif" alt="bar" />
To include a stylesheet from a view, you can use an absolute path like the example below. Although, you may import your stylesheets unlike I do.
<link href="/css/foo.css" rel="stylesheet" type="text/css" media="screen" />
To include an image from a stylesheet, guess what? You can use an absolute path like the example below.
body {
background: #ffffff url('/images/foo.gif') no-repeat top left;
}
Keep in mind that it’s not impossible to use a relative path for anything above. I just find it a lot easier to use an absolute path since most of my assets are one or two directories from root.
Posted in CodeIgniter | No Comments »