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

Hi there!
I'm totally new to CI and know little about html/php,when I read CI user guide,
a section of code in tutorial/news section confused me:

Code:
<h2><?php echo $title; ?></h2>
<?php foreach ($news as $news_item): ?>
        <h3><?php echo $news_item['title']; ?></h3>
        <div class="main">
                <?php echo $news_item['text']; ?>
        </div>
        <p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a></p>[code]
<?php endforeach; ?>
[/code]

Where does the 'class="main"' come from? Where can I edit it?
Anyone who answers will be a great help to me.
Thanks!!
Reply
#2

(09-15-2015, 07:46 PM)folospace Wrote: Hi there!
I'm totally new to CI and know little about html/php,when I read CI user guide,
a section of code in tutorial/news section confused me:


Code:
<h2><?php echo $title; ?></h2>
<?php foreach ($news as $news_item): ?>
       <h3><?php echo $news_item['title']; ?></h3>
       <div class="main">
               <?php echo $news_item['text']; ?>
       </div>
       <p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a></p>[code]
<?php endforeach; ?>
[/code]

Where does the 'class="main"' come from? Where can I edit it?
Anyone who answers will be a great help to me.
Thanks!!
class="main"

Main is the class name of the div tag.

it can edit in the css page or same page.
Practice | Practice | Practice
Reply
#3

(09-15-2015, 07:46 PM)folospace Wrote:
Code:
<div class="main">
   <?php echo $news_item['text']; ?>
</div>
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:
Code:
#main {
   font-size:150%;
   font-weight:bold;
   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!
Reply
#4

(09-15-2015, 11:44 PM)RobertSF Wrote:
(09-15-2015, 07:46 PM)folospace Wrote:
Code:
<div class="main">
   <?php echo $news_item['text']; ?>
</div>
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.



Thanks a lot ! You make my mind clear, Now I get what it is ! Good luck with you !
Reply




Theme © iAndrew 2016 - Forum software by © MyBB