Welcome Guest, Not a member yet? Register   Sign In
Equivalent of 'include' statement
#1

[eluser]Bionicjoe[/eluser]
I have two view files, one for just looking at a ticket and one for editing a ticket. I'm re-using a bunch of the same code in each file.

What is the best way to do this so I don't need to layout the same field data in each view file?

File 1 (plus there's a bunch more fields set up this way)
Code:
$ticketnumber = array(
              'name'        => 'ticketnumber',
              'id'          => 'ticketnumber',
              'maxlength'   => '15',
              'size'        => '25',
              'style'       => 'width:25%',
            );

File 2 (same fields plus a value attribute)
Code:
$ticketnumber = array(
              'name'        => 'ticketnumber',
              'id'          => 'ticketnumber',
              'maxlength'   => '15',
              'size'        => '15',
              'style'       => 'width:25%',
              'value'       => $row[0]->ticketnumber,
            );

Creating a file to include and using this didn't work. (loading at beginning of view file)
Code:
$this->load->file('system/application/include/outageview_inc.php', false);
#2

[eluser]rbnc[/eluser]
Defining arrays should be done at a controller level.

I'd create a helper function for making these arrays and call it in the controller and pass it into the views.

Smile
#3

[eluser]Clooner[/eluser]
To load a view file inside a view use
Code:
$this->load->view('viewfile');
#4

[eluser]John_Betong[/eluser]
[quote author="clooner" date="1277308478"]To load a view file inside a view use
Code:
$this->load->view('viewfile');
[/quote]

Sometimes I use this quick way inside a view and it works Smile
Code:
<?php echo include '_view_snippet_to_include.php';

What are the advantages or disadvantages?
 
 
 
edit spelling
#5

[eluser]Clooner[/eluser]
[quote author="John_Betong" date="1277317936"]
Sometimes I use this quick way inside a view and it works Smile
Code:
<?php echo include '_view_snippet_to_include.php';

What are the advantages or disadvantages?
[/quote]
You'll be able to pass parameters to it and it goes through the loader/output procedures of CI which makes you be able to use hooks or overwrite it... Basically it will be more flexible!
#6

[eluser]John_Betong[/eluser]
Quote:Clooner - 23 June 2010 09:45 PM

You’ll be able to pass parameters to it and
it goes through the loader/output procedures of CI
which makes you be able to use hooks or overwrite it…

Basically it will be more flexible!

Many thanks - now that has got me thinking Smile

 
 
 




Theme © iAndrew 2016 - Forum software by © MyBB