Welcome Guest, Not a member yet? Register   Sign In
Views within Views
#1

[eluser]kevinprince[/eluser]
Im stuck and have been for a hour or so, im building a newsletter generator, which outputs in a text box.

If i do $var = $this->load->view('newsletter', $data);

It loads the view, and doesnt seem to keep it in PHP, for the actual view call.

Any Ideas?

Kevin
#2

[eluser]Tom Glover[/eluser]
This is how I create a similar function.

Template file
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;&lt;?php echo $title?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
//Template Code around this
<div id="content">
        <div id="right">            
&lt;?php echo $content ?&gt;
</div>    
        <div id="left">
            &lt;?php echo $left?&gt;                    
        </div>        
    </div>
&lt;/body&gt;
&lt;/html&gt;

The left view file: (Simple Login)
Code:
&lt;?php
if ( $logged == true){
$message = 'You are logged in as:'.get_user_data("user_name");
echo $message;
echo "Log Out";
}else{
echo 'Login to OPMS:';
echo $form;
}
?&gt;

The Right Content:
Code:
<h2>Welcome to O<em>PM</em>S</h2>
<p>Welcome to OPMS the project management software from WackyWebs.net. To access this site you will need to login, using the username and password supplied by WackyWebs.net. This site is for clients of Website Design and Web Development by WackyWebs.net.</p>
<p>To Access a Demo of OPMS please contact &lt;?=safe_mailto('[email protected]','sales')?&gt; . </p>

and finally the controller that brings it all together:

Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    function index()
    {
        $data['logged'] = false;
        $this->load->helper('url');//ignore this used in my file only, unless needed.
        $template['title'] = "Welcome to OPMS";//title
        $template['left'] = $this->load->view('login',$data,true);//left content
        $template['content'] = $this->load->view('home','',true); //right content
        $this->load->view('template', $template);//main template to load other data
    }
Hope this Helps!

EDIT:
By the way all you needed to add in the $var is True to return the file as a string not and output, this will then allow you to output it by echoing the $var where you need it. this is shown in the example above.
#3

[eluser]sophistry[/eluser]
the faq will be your guide
#4

[eluser]kevinprince[/eluser]
So so stupid of me!

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB