Welcome Guest, Not a member yet? Register   Sign In
Problem with model
#1

[eluser]Razvan V[/eluser]
Hello,

In one of my controller's functions i get data from a model via a funtion, and put the data in a string.

Code:
$continut = $this->biography->getEntries();

the getEntries() funtion looks like this:
Code:
function getEntries(){
  $i=0;
  $query = $this->db->query("SELECT * FROM biografie ORDER BY data DESC");
  foreach ($query->result() as $row){
   if ($i % 2 ==0){  
    $this->continut .='
    <div id="bioleft">
    <div class="bioheader">
      <h1 class="biofloat2">' . $row->titlu . '</h1>
    </div>
    <div class="rightline2">
     <p class="dreapta">' . $row->subtitlu . '</p><br /><br />
     <p class="dreapta">' . nl2br($row->continut) . '</p><br />
    </div>
    </div>
    ';
    $i++;  
   }else{
    $this->continut .='
    <div id="bioright">
    <div class="bioheader2">
      <h1 class="biofloat">' . $row->titlu . '</h1>
    </div>  
      <div class="rightline">
      <p class="stanga">' . $row->subtitlu . '</p><br />
      <p class="stanga">' . nl2br($row->continut) . '</p> <br />
    </div>
    </div>
    ';
    $i++;
   }    
  }
  
  return $this->continut;
}

The problem is the folowing:

If I modify my database and just fo to the function via link it dosen't show what changes i made in the data base, only a refresh can fetch my data corectly.

I am new to codeigniter, and allso i am a bad writer.

Hope u can understand what i ment.
Please HELP!
#2

[eluser]Razvan V[/eluser]
Correct me if i am wrong MVC works this way:

The view sends a HTTP request tot the controller, the controller accesses a model, and sends data back to the view.

Since the view is something hat the user can see, best practice says that u should never sent data about you're database, or connect directly in the database in the view.

I wanted to do something with jquery and refresh the <div> where i put the data every second, and it worked great, except 1 thing.

I got the data(the one that i intended to put in the div) form a function in the controller, and the data didn't refresh, so if i went to the function that posted the data and hit F5 then the string would update on my main page... From my point of view it is the same problem as the one above..




PS: at the moment the website is running on localhost. Would this problem disappear if i put it online? From what i know it shouldn't matter, but I don't know...
#3

[eluser]Razvan V[/eluser]
bump...

I really need a answer Sad...
Nobody?
#4

[eluser]Razvan V[/eluser]
bump...
#5

[eluser]Razvan V[/eluser]
really nobody ???

Sad
#6

[eluser]alexwenzel[/eluser]
[quote author="Razvan V" date="1349765170"]
Correct me if i am wrong MVC works this way:
The view sends a HTTP request tot the controller, the controller accesses a model, and sends data back to the view.
[/quote]

MVC for my understanding works that way:

- the application calls the controller
- the controller calls the model
- the model returns data to your controller
- the controller calls the view
- the view displays the html / css / js

Its totally wrong to put html and stuff in your model. those things belong into the view.
#7

[eluser]alexwenzel[/eluser]
I can recommend my model for codeigniter for an easier integration with database.
I have also some examples in my bitbucket wiki.

http://ellislab.com/forums/viewthread/223845/
#8

[eluser]Razvan V[/eluser]
[quote author="alexwenzel" date="1349952974"][quote author="Razvan V" date="1349765170"]
Correct me if i am wrong MVC works this way:
The view sends a HTTP request tot the controller, the controller accesses a model, and sends data back to the view.
[/quote]

MVC for my understanding works that way:

- the application calls the controller
- the controller calls the model
- the model returns data to your controller
- the controller calls the view
- the view displays the html / css / js

Its totally wrong to put html and stuff in your model. those things belong into the view.[/quote]

HTTP request means that a form was send, ie the application calls the controller via a form submit, the controller calls the model and the model returns the result to the controller witch passes the information to the view.

What you wrote is exactly what i wrote...Sad

If my knowledge of MVC is correct then why does codeigniter need a refresh to show the correct data?
#9

[eluser]alexwenzel[/eluser]
if its like that then you have a logical mistake in your application flow.

Maybe you displaying the old data. the one before you updated the database record ?!
#10

[eluser]Razvan V[/eluser]
that is the problem Sad i don't think i am doing it wrong...

I call the getEntries() furnion and i send the string it returns to the controller.
Then the controller passes the string in the view...

Is it posible that the porblem is the fact that the borwser is showing old data?

at the first acces of the website the data si shown correctly


thanx for taking the time to help me Smile




Theme © iAndrew 2016 - Forum software by © MyBB