Welcome Guest, Not a member yet? Register   Sign In
A simple CI tutorial question

(09-15-2015, 07:46 PM)folospace Wrote:
<div class="main">
   <?php echo $news_item['text']; ?>
Where does the 'class="main"' come from? Where can I edit it?

Hi, and welcome to everything, Codeigniter, HTML, PHP, CSS, and the forum! Smile

Anyway, I think that class is an oversight in the tutorial because it's not actually defined anywhere. I'll explain briefly what it is, but it actually has nothing to do with Codeigniter. It tripped you up because you're learning everything at once.

As you now know, there's HTML and PHP, but only what's between <?php and ?> is PHP. Everything outside those bracketing devices is not PHP. In this case, the two lines with "div" in them are HTML. So what's that class="main" part?

That would be a class in a language called CSS, the purpose of which is to format the visual appearance of the information presented. So either in a separate file or in the same file (there are several ways to include the actual CSS code in your web pages), there is a CSS class called "main" that applies some particular format. CSS is not difficult but getting it to cooperate can require fussing. The CSS class "main" might looks something like this:
#main {
   border: 10px solid;

If that were the class, then everything echoed by $news_item['text'] would appear 50% larger, bolded, with a fairly thick border around it.

Now imagine that instead of a div that references the CSS class "main," you had embedded HTML or even CSS code directly into each view file you had. On a big project, that could be hundreds of view files. Then imagine the client or the boss says, "I don't like the border ten pixels wide. Make it just eight." You would then have hundreds of view files to edit, and maybe your global search and replace found everything and hopefully it didn't change what didn't need to be changed.

But if you had used class="main" in your HTML, then you just go to the class file itself and change the border: 10px solid; to border: 8px solid, and that's it.

So, for now, don't worry about it. You may have noticed the tuturial worked fine without it. Bad or even missing CSS won't make your application crash, though you'll need to learn CSS too, of course. 
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!

Messages In This Thread
A simple CI tutorial question - by folospace - 09-15-2015, 07:46 PM
RE: A simple CI tutorial question - by RobertSF - 09-15-2015, 11:44 PM
RE: A simple CI tutorial question - by folospace - 09-16-2015, 02:22 AM

Theme © iAndrew 2016 - Forum software by © MyBB