Welcome Guest, Not a member yet? Register   Sign In
Loading boxes
#1

[eluser]Unknown[/eluser]
Hi, *Sry for bad english* :-)

I want to have a function which includes a view file with a css Box.
This function also have to get informations from the db and put this infos in the box.

Now comes my problem:
I want those boxes all over my page with different informations from different tables of my database.

So my question is (i am an absolut newbee with ci). Must I realize this function with a model? And where must I insert the view file? In the function? Or in the view file of my global Website?

Thx for help.

Mikesh
#2

[eluser]Colin Williams[/eluser]
From what I understand, you will have one View that displays all boxes. Then, you'll have one View for each kind of box (assuming there are different kinds of boxes). Information about these boxes would be stored in a database, so you would have a Model to interact with this data. Finally, the Controller would be responsible for fetching the needed boxes and passing them onto the appropriate Views, finally displaying the main View that lists all the boxes.

Code:
class Boxes extends Controller {

function list_boxes()
{
   $this->load->model('boxes_model');
   $boxes = $this->boxes_model->get_user_boxes();
   $data['boxes'] = array();
   foreach ($boxes as $box)
   {
      $data['boxes'][] = $this->load->view('boxes/'. $box->type, array('box' => $box), TRUE);
   }
   $this->load->view('list_boxes', $data);
}

}

That's a pretty basic mock-up. I'm sure you'll find added complexity (especially in the Model) as you continue.
#3

[eluser]Unknown[/eluser]
Oh, That's nice.

But if i want to put this controller in my main Controller, how can I import it?

For example: I have my Home.php - Controller. This Controller loads my site, with the Content of the Home Site.
Now I also have my box.php Controller. How can I combine them to one? So that I have a Home Site with boxes in there at the end.

Thx foh help
Mikesh
#4

[eluser]m4rw3r[/eluser]
Move the "box methods" into the home controller, and use routing if you want other uris.

But separating the home controller and the box controller may be a better idea, depending on how your app is designed.




Theme © iAndrew 2016 - Forum software by © MyBB