CakePHP: Dynamic Content in Layout

CakePHP

I was working on my first CakePHP project. I created a layout for the project and I realized that the layout was the same for multiple pages in the application – only the content was different. At first, I began to duplicate the layout for the other pages and changed the content accordingly. This didn’t make sense – I hate repeating the same code. CakePHP did not seem to have a way to create dynamic content within a layout. My first thought was to create the project using CodeIgniter’s, but I really wanted to create a web application using CakePHP.

After struggling to find a solution, I finally found the the correct way to create dynamic content with CakePHP.

Note: This post has been rewritten. When I first created this post, I was new to CakePHP. The original post did not display the best solution for creating dynamic content, so I rewrote it.

Continue reading

Checkout My New Site - T-shirts For Geeks

Defining Constants With CodeIgniter

Codeigniter

I am fairly new to the PHP framework scene. I have been using CodeIgniter for about 3-4 months and I have found it to be quite straightforward.  I have been able to develop websites quickly using an understandable structure.

When I first began defining constants with CodeIgniter, I used a method that I learned in the book, “Professional CodeIgniter
“. I placed all of my constants at the bottom of the config.php file (system/application/config/config.php).

$config['jquery_assets'] = 'assets/js/jquery/';

To access the configuration item in my application, I would write something like:

$this->plugin = base_url() . $this->config->item('jquery_assets') .'imgooglemaps/jquery.imGoogleMaps-0.5.js';

While this works fine, I really wanted to define constants in the traditional PHP way. I recently noticed a file named constants.php (system/application/config/constants.php). Here, I am able to define application constants like a traditional PHP application.

define("GAL_THUMB_MAX_W", 120);

I think that I will use the constants.php file from now on.

Checkout My New Site - T-shirts For Geeks