Welcome Guest, Not a member yet? Register   Sign In
best practice question
#1

[eluser]k2zs[/eluser]
Hello all,

Is it ok to use "this->load->view('view_name')" from within a view much as one would use an include in standard php? I know it works but is it an accepted practice or would it be better to just use an include statement.

Thanks
#2

[eluser]seeraw[/eluser]
Hi k2zs,

I will better if you follow CI standard.
Both the ways are correct to load any other file but you should use this->load->view(‘view_name’) to load the file.

Thanks,
Swapnil
#3

[eluser]k2zs[/eluser]
[quote author="seeraw" date="1299000506"]Hi k2zs,

I will better if you follow CI standard.
Both the ways are correct to load any other file but you should use this->load->view(‘view_name’) to load the file.

Thanks,
Swapnil[/quote]

so it is ok to load a view from within a view?
#4

[eluser]seeraw[/eluser]
[quote author="k2zs" date="1299000951"][quote author="seeraw" date="1299000506"]Hi k2zs,

It will better if you follow CI standard.
Both the ways are correct to load any other file but you should use this->load->view(‘view_name’) to load the file.

Thanks,
Swapnil[/quote]

so it is ok to load a view from within a view?[/quote]

Yes correct
#5

[eluser]daparky[/eluser]
I load common partials in controllers and then any extras in the view files where need be. So yes, it's ok to do so.
#6

[eluser]kilishan[/eluser]
And that is exactly how ExpressionEngine does it, too. If the creators of CodeIgniter do, you're probably good. Smile
#7

[eluser]k2zs[/eluser]
Thanks all,

That's what makes CI so great, it's community! Smile
#8

[eluser]Derek Allard[/eluser]
I wrote a good chunk of EE2 when I worked for EllisLab, and the big advantage of using $this->load->view('foo') instead of an include that I saw is that you can then pass view variables into it.

Code:
//controller
$this->load->vars(array('var1'=>'val1', 'var2'=>'val2'));
// and in any view
<?php echo $var2;?>




Theme © iAndrew 2016 - Forum software by © MyBB