Linking Snippets in Codeigniter – PHP

Since I have been attending LAMP Camp, I have been learning PHP and MySQL and using MVC frameworks to build web applications. I’m about to start my 6th week tomorrow, so I’m already halfway through! It’s a free 12-week immersive program in Atlanta, that you can read more about here.

To get your certificate of completion, you have to create a personal portfolio site using what you’ve learned. Since we have to use an MVC framework for our project, I’ve chosen Codeigniter since they have a tutorial that comes with the download. Their tutorial is very easy to follow and they teach you how to also connect to a database.

Today I spent my time on the views and getting the Bootstrap Carousel feature to work. I also learned how to link pages together. If you are using the MVC framework Codeigniter for your PHP web application, you can link page views without touching your controller file.

I saved my ‘snippet’ views in their own folder in ‘views/templates’ and just linked to them where I wanted them to appear. Since I worked on the carousel feature today, I put the carousel code in its own file called carousel.php. Then, I added the following code to my home.php view file where I wanted the carousel to appear:

 <?php $this->load->view("templates/snippets/carousel.php"); ?>

This is my controller file that loads the home.php view:

public function view($page = 'home')
  if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
  // Whoops, we don't have a page for that!

  $data['title'] = ucfirst($page); // Capitalize the first letter

  $this->load->view('templates/header', $data);
  $this->load->view('pages/'.$page, $data);
  $this->load->view('templates/footer', $data);

Added Stripe gem to Rails app

Part VII of Codermanual is broken into three different sections. I’ve just completed the first two and am extremely excited about how my Rails app is coming along! We integrated Stripe, Devise, and Figaro gems into our app to add secure, authentic credit card payment to our membership site.

  • To use Stripe, you will need to sign up for a free account on their website: 
  • Devise is an authentication gem. Read more about how to integrate it into your Rails app here.
  • Figaro helps you securely configure your Rails application.

Web application views

The home page:
heroku codermanual app

Alert for user sign-out:
Unnamed QQ Screenshot20150819055708

The sign-up screen for the Pro account:
pro account rails application

The sign-up screen for the Basic account:
basic account rails app