Pleeease: Help me with Site Structure - from one page example, to a multipage example

#1
[eluser]MEM[/eluser]
Hello, I'm trying do develop my first site with CI. I'm new to MVC, CI, PHP and OOP in general. However, I'm making my way to those.

I've read a LOT on those forums threads by search the Keyworks "Site Structure", and also google a lot on those subjects, still can't find my way to go.

To make this worst, I have follow some tutorials that, actually, teach you the basic, but never give your the wide picture. You know how to add, remove, delete, use the mailer class or other things like that, but you still don't know how to work will multiple controllers and views. And, this is, à mon avis, one of the worst steps to accomplish: Understanding the wide strutucture of creating a website.

Because of all this, I'd like to ask your comprehension and help on this:

Based on some tutorials online I'm now close to this structure for a hypothetical product list page:

header_view.php
Code:
<div id=”header”
    <h1>&lt;?php echo $header;?&gt;</h1>
    <p>this is my header</p>
</div>

content_view.php
Code:
<div id=”content”
    &lt;?php foreach ($products as $product):?&gt;
        <p><strong>Name:</strong>&lt;?php echo $product->name;?&gt;</p>
&lt;?php endforeach;?&gt;
</div>

footer_view.php
Code:
<div id=”footer”
    &lt;?php echo $footer; ?&gt;
    <p>o this is my footer</p>
</div>


Code:
Class Page extends Controller
{
  function Page()
  {
    parent::Controller;
    $this->load->model(‘Product’)
  }

  function  índex()
  {
    $data[‘header’]=$this->load->view(‘header_view’,array(‘header’=>’Header Zone’), TRUE);
$data[‘content’]=$this->load->view(‘content_view’,array(‘product’=>$this->Product->getAll() ), TRUE);
    
    $data[‘footer’]=$this->load->view(‘footer_view’,array(‘footer’=>’Footer Zone’), TRUE);

    $this->load->view(‘main_page’, $data);
   }
}

Finally I would have some kind of wrapper, like this, where all those components will be called.

Code:
<!DOCTYPE html PUBLIC …..
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
    <div id=”container”>
        &lt;?php echo $header.$content.$footer;?&gt;
    </div>
&lt;/body&gt;
</htm>


I'm trying to pass from this structure,to a structure that allows me to deal with several pages.

I'm not actually developing, only mockup the structure so, no deep code needed.


WHAT I DO SEE:
content_view.php is quite related to products, so maybe I will change the name to produt_view.php and then have other views as well.

The Class Page that extends Controller could also be renamed as product_list_controller and I will add other controllers for other pages as well...

To the wrapper I would call it product_list_view but again, I will end up with other views as well..


I could also think on having a controller class called institutional, and on each method on that controller class, I would point to a static page view.


I'm lost and desperate. Please help me out.

Please advice,
Márcio

#2
[eluser]jedd[/eluser]
Here are my favourite threads that I suggest to people who haven't found any hits in the forum search on 'header' and 'footer' - but there are hundreds more threads on this subject to choose from, if you don't like these two:
[url="http://ellislab.com/forums/viewthread/109698/"]http://ellislab.com/forums/viewthread/109698/[/url]
[url="http://ellislab.com/forums/viewthread/110969/"]http://ellislab.com/forums/viewthread/110969/[/url]

#3
[eluser]MEM[/eluser]
Thanks jedd.


I've also found those:
http://ellislab.com/forums/viewthread/106945/P0/

http://ellislab.com/forums/viewthread/108810/

This for admin section:
http://ellislab.com/forums/viewthread/102960/P0/


I still have no luck. Sorry. Maybe I need some rest of all this for a while.

Thanks anyway,
Márcio

#4
[eluser]gwelter[/eluser]
Jumping into CodeIgniter without knowing PHP or OOP might be kind of like performing surgery before you've been to med school... If you want a strong foundation, you might want to tackle PHP first.

That being said, what exactly is your question? What are you seeing when the page loads? Are there any errors displayed or in the log? I don't see why your setup wouldn't work offhand, so my only guess is a syntax error somewhere.

I wonder why you're trying to load the views as data, though, since you're not doing anything with the data. You could just call:
Code:
$this->load->view('wrapper_top');
$this->load->view('header_view',array('header'=>'Header Zone'));
$this->load->view('content_view',array('product'=>$this->Product->getAll()));
$this->load->view('footer_view',array('footer'=>'Footer Zone'), TRUE);
$this->load->view('wrapper_bottom');

Or, more logically, include the wrapper portions in your header and footer. Hope that helps.

#5
[eluser]fesweb[/eluser]
Actually, templating is more what you're looking for. Anything else is not really going to satisfy you.

There are other tools available, but I explain my preferred, simple, solution here:
http://ellislab.com/forums/viewthread/97702/

#6
[eluser]MEM[/eluser]
I have been on PHP OOP I was trying to make my way to a personal framework, and then I die on the MVC model. Confused
And trying to deal with Pagination, Validation, Login classes all together and related...WOW, nightmare, so... I'm trying to keep learning OOP, more PHP, MVC but using the CodeIgniter help. Smile

Normally I don't rush to the code, and I stay 70% or 80% of the development time over the structure. So I can't see any error for now, because I'm just trying to understand how the skeleton on this work.

The best I can find is Validation with Codeigniter, Pagination with Codeigniter, Anyspecificmodules with codeigniter, but, the big one, the ALL, the A Website Struture with Codeigniter the best I can find are "half" blogs that promisse a all revision but die on the introdution.

I will never forget this past days, and I'm sure one day I will create a "Example Complete Structure on a Common Website with Codegigniter". Smile

The template helps me structurating the views, and have views separed from logic, but I also need a way to learn, how to structure the controllers. But please, no more links. I have a lot already. Smile


I will consider all your replies, and I will rest for some hours and then, try to come back with a structure code based on your replies.


Thanks a lot,
Márcio


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.