How to load pages from both files and the database

Description

Transcript

Now, let's take a look at the code behind this. First of all, we'll look at the configuration options for the page CRUD system. So I'm going to go back to the site folder here and in pages, let's go ahead and look at the pages.

php file in the admin folder. And you see, we begin this process the same way that we did both our users and our products files. We set a title and we set some options.

Let's go through the options briefly. We set the table, the item_name, the display_columns which is, again, aligned with what we see on the listing page. We have our id_column which is the unique identifier.

Our default_sort_column for the listing page. And then our add_edit_columns which determines what inputs we're going to see on the edit form. Now, for the most part, you'll recognize everything here.

But we have one additional attribute that we're passing which is type. Now before, the only input that we offered was the text input. So no matter what type of content we were dealing with manipulating, it was all going to end up in a text input.

Now, we're supplying this type attribute so we can offer both the text input and the text area. Eventually, as we matured this script, we'd add support for radio buttons, check boxes, select boxes and so on. If we want to take a look at how this is being processed in our CRUD script, we can open up crud.

php. So, I'm going back to the site folder and it includes, I'll open up crud. php, and let's do a search here for type.

So, right here is our first instance of it. It says if isn't set the columns options type, then we'll set it to a default of text. So, this is in our add_edit_form as we would expect it to be.

And this is basically just setting the default to text. As we scroll down, we'll see this used one more time right here where we switch based on the type. Now, text is the default.

It's what we were building in our previous script all of the time. And so, we'll render the input as a text input. If something isn't set for this or we explicitly set the type to text.

But if it's text area then we'll build the text area. We're pulling in the same attributes here like the id and the name, and then the content we're displaying within the text area tag. Because it works just a little differently than it does for text input.

We also need to pass this through HTML entities, which will convert characters like left and right arrows and quotes into HTML entities so we can edit it directly in here without our browser interpreting any of it as potential HTML tags or characters. So this way, we can safely use HTML within our text area and then display it here later as we're editing the content without it displaying as HTML. It will display as plain text here.

When you have an active membership, you will be able to see your progress here.

Skill focus: ProgrammingSkill level: Beginner - Advanced

In this collection, we walk you through everything you need to know to build rich PHP applications and work with PHP code in Drupal. These videos are designed to bridge the gap between Drupal site builders and programmers. We guide you gently through the basics of PHP, and work our way into building more and more complicated scripts. In our final example we build a custom CMS, which will help you understand the architecture of Drupal while flexing your new PHP skills in a practical way.

To follow along with these videos, you will need a web environment set up on your computer. Follow the videos in Setting Up a Web Environment With Drupal to get an environment set up on Windows, OSX (Mac) or Linux.

Some of the key points we'll be covering include:

How to work with variables and functions

How to use logic in PHP like if…then statements and looping

How to build forms in PHP

How to store persistent data in sessions

How to work with MySQL

How to build a simple CMS from scratch

Who this collection is for

This collection is for those that want to learn PHP programming. You may want to learn PHP to work with Drupal in particular, but what you learn will be useful for any project you work on requiring a background in PHP.

It looks like there might be an issue playing videos in this browser. We're working on better cross-brower experience, but in the meantime please try the latest Chrome or Firefox browsers. Or, you may be able to watch the video directly without progress tracking or transcript: