Welcome Guest, Not a member yet? Register   Sign In
What's the best approach to achieve this?
#1

[eluser]ReyPM[/eluser]
Hi, I'm developing a module for PyroCMS which is built on top of CI but have a problem and post here hoping someone give me some ideas or just help to find a solution. I have a code for get some data from DB and then need to mix the results from this query to some HTML code. See a example below:
Code:
$query = mysql_query("SELECT * FROM tbl");
while ($row = mysql_fetch_array($query)) {
   echo "<div>" . $row['field'] . "</div>";
}

But this is a ugly approach and I don't want this because it breaks the MVC pattern completely. So I think in pass the data to one view (didn't know if I can handle partials here at CI) and return it as data. For example:
Code:
$data['query_results'] = mysql_fetch_array($query);
$this->load->view('myview', $data, true);
Then my question is: if I load the view and return it as data, which will be the result? The entire HTML code of that view including results from the processed data or what? Any other approach to get this working?

Cheers and thanks in advance
#2

[eluser]CroNiX[/eluser]
Why aren't you just using the built in database class instead of hand rolling it?

As far as your last question:
Code:
$this->load->view('myview', $data, true);
would return the RENDERED view as a variable, so you would need to assign it to a variable
Code:
$myview = $this->load->view('myview', $data, true);

Then
Code:
echo $myview;

or (pass it to another view, where you would echo the 'myview' variable (containing the other view) where it needs to go...
Code:
$data['myview'] = $this->load->view('myview', $data, true);
$this->load->view('master_template', $data);
And in your master_template.php, just

Code:
<div id="menu">&lt;?php echo $myview; ?&gt;</div>

or whatever...
#3

[eluser]ReyPM[/eluser]
@CroNiX thanks for your reply. For the first was just a sample for yours to see what I'm trying to do Wink I'll try this suggestions and come back to says thanks again if all works fine or to ask again if not.




Theme © iAndrew 2016 - Forum software by © MyBB