Welcome Guest, Not a member yet? Register   Sign In
Best way to work with Smarty
#1

[eluser]Unknown[/eluser]
Hi there! My name is subzeromb and this is my first message in the forum Smile I am working with codeigniter during one month and it is amazing.

Now I have installed smarty, everthing works fine. My question is about the way to work with it. It is very usual see in the codeigniter user guide things like this in the view file:

Code:
<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

<h5>Username</h5>
&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="50" /&gt;

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;

I would like to ask you what is it the best way to deal with these situation when you are working with smarty. I mean the part of php code inside of view file. I know that smarty can include php if you write the code inside of {php} tags but it doesn't look like the most professional way to do it.

By the other hand, it is possible to pass these php code by the controller, something like:

Code:
$data['errores'] = validation_errors();
$data['form'] = form_open();
$data['value_username'] = set_value('username');

$this->mysmarty->view('mensaje', $data);

And the view

Code:
{$errors}

{$form}

<h5>Username</h5>
&lt;input type="text" name="username" value{$value_username}" size="50" /&gt;

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;

But this way looks very complicated and it takes time to declare the variables for smarty. I just want to know if some one can give me some light on this to see what it is the best way to use smarty in codeigniter.

Thank you!
#2

[eluser]timtheelephant[/eluser]
I'm curious as to why you're even bothering to use Smarty. CI is very friendly for templating as-is.
However, here's what appears to be a good article on the subject.
#3

[eluser]behnampmdg3[/eluser]
Can anyone explain this?
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB