Welcome Guest, Not a member yet? Register   Sign In
What's wrong with this code?
#1

[eluser]fatdog[/eluser]
Hi,
I'm new with CI and MVC, so please keep that in mind.
What's wrong with this code on the controller?

Code:
function index() {
        $this->load->model('proyects_model');
        $data['proyectos'] = $this->proyects_model->get_proyects($some_params);
            
        $this->load->model('news_model');
        $data['novedades'] = $this->news_model->get_news($some_params);
        
        $this->template->load('template', 'home_view', $data);        
}

When I output the results in the view, the results are "adding up" the results from the models.
Meaning that the output should be like:

PROYECTS
- TABLE WITH PROYECTS

NEWS
- TABLE WITH NEWS

Instead I'm getting this:

PROYECTS
- TABLE WITH PROYECTS

NEWS
- TABLE WITH PROYECTS
- TABLE WITH NEWS

Thanks
#2

[eluser]Colin Williams[/eluser]
For one, you should use $this->load->view(); and not $this->template->load(); Is $this->template the instantiation of some Template class you are using?
#3

[eluser]fatdog[/eluser]
Yes, it's a template library I'm using. But that's not the problem.
If I do a simple echo directly from the controller, bypassing the template and view, I still get the "adding up" issue.
#4

[eluser]Colin Williams[/eluser]
Then, there's no way to know with the limited amount of code you've provided. Could be how you're outputting them, could be bad queries, etc.
#5

[eluser]GSV Sleeper Service[/eluser]
are you using the HTML Table class in your model? if so, you have to call table->clear() between the table->generate()'s
#6

[eluser]fatdog[/eluser]
[quote author="GSV Sleeper Service" date="1231991836"]are you using the HTML Table class in your model? if so, you have to call table->clear() between the table->generate()'s[/quote]

Yes, that was it.
Thanks a lot.
#7

[eluser]Tom Glover[/eluser]
Next time you would get a faster response if you provide more code for us to analyze, also where you think the problem may exist.
#8

[eluser]fatdog[/eluser]
[quote author="Tom Glover" date="1231993475"]Next time you would get a faster response if you provide more code for us to analyze, also where you think the problem may exist.[/quote]
Faster? Dude, It took less than an hour to solve the issue. Awesome response time by my standards.

In any case, you are right, I should have been more detailed. I guess I thought I was making a very obvious newbie mistake.




Theme © iAndrew 2016 - Forum software by © MyBB