Welcome Guest, Not a member yet? Register   Sign In
Explantion of {elapsed_time}
#1

[eluser]Grind[/eluser]
If you download Codeigniter and view the welcome_message.php file you see at the bottom of the page the following code:
Code:
Page rendered in {elapsed_time} seconds

Where does {elapsed_time} refer to? Is it possible to make such thing for displaying a guestbook, like {guestbook}?

Thanks.
#2

[eluser]rogierb[/eluser]
Check out the benchmarking class in the userguide. You will find the answer there.
#3

[eluser]Grind[/eluser]
Thanks. I now understand the elapsed time-bit. But is it possible to make a pseudo-variable for a guestbook? This would dramatically decrease the amount of PHP-code in the view-file.
#4

[eluser]rogierb[/eluser]
You can if you extend the output class.
But that might not be the best option, why not use a 'normal' variable to pass to the view?
#5

[eluser]Grind[/eluser]
Could it be achieved with one variable then? Now I have a foreach-loop in the view-file to display the guestbook, but that amount of PHP-code could be less? Where can I find how I do this? I'm still learning Codeigniter.
#6

[eluser]rogierb[/eluser]
Just cut the php code from your view, stick it in the controller (method) and put is in a variable. Then pass it to the view.

Code:
private function guestbook()
{
// do whatever you did in the view.
}

/* normal method */
$data['guestbook_var'] = $this->guestbook();
$this->load->view('my_view', $data)

/* view */
echo $guestbook_var;
#7

[eluser]Grind[/eluser]
Thanks for your reply. That's a lot better. But it doesn't work for a 100%.
My guestbook-function looks something like this:

Code:
private function guestbook()
{
    $this->db->order_by('id DESC');
    $query = $this->db->get('guestbook')
    foreach($query->result() as $row)
    {
        echo "<h3>".$row->name.'</h3>';
    }
}

But the guestbook is shown, even if the variable $guestbook isn't echoed in the view-file. Besides, the guestbook-function is echoed before loading the page. So if I look at the source I see all the guestbook-entries and after that the &lt;html&gt; and &lt;head&gt;-tags etc. So something is wrong.
I think I don't need to echo anything in the guestbook-function, but how does it work instead?

Thanks for your help.
#8

[eluser]rogierb[/eluser]
hi,

Don't echo in your controller, only in a view files. If you echo in you controller, you output before the headers and html.

Code:
$guestbook .= "<h3>".$row->name.'</h3>';

$guestbook = '';
foreach($query->result() as $row)
{
    $guestbook .= "<h3>".$row->name.'</h3>';
}

return $guestbook;
#9

[eluser]Grind[/eluser]
How obvious. Thank you very much!




Theme © iAndrew 2016 - Forum software by © MyBB