Welcome Guest, Not a member yet? Register   Sign In
How can I want pass a string with the view content instead of a file name when loading a view?
#1

[eluser]frankabel[/eluser]
Hi all,

I just want make something like:

Code:
$this->load->view($str_with_view_content, $data, TRUE);

instead of:

Code:
$this->load->view('path_of_view_content', $data, TRUE);

What options I have to archieve this?

Thanks in advanced.
Frank
#2

[eluser]TWP Marketing[/eluser]
[quote author="frankabel" date="1348533897"]Hi all,

I just want make something like:

Code:
$this->load->view($str_with_view_content, $data, TRUE);

instead of:

Code:
$this->load->view('path_of_view_content', $data, TRUE);

What options I have to archieve this?

Thanks in advanced.
Frank[/quote]

Place the variable: $str_with_view_content, inside your data array:

Code:
...
$data['str_with_view_content'] = $str_with_view_content;

$someview = $this->load->view('path_to_a_view_file', $data, TRUE);
...
#3

[eluser]frankabel[/eluser]
With "str_with_view_content" I mean a string that have the html with PHP tags inside. So, what I want is avoid load the content from a file, and load it from a string var.
#4

[eluser]CroNiX[/eluser]
http://ellislab.com/codeigniter/user-gui...utput.html
#5

[eluser]frankabel[/eluser]
Thanks all for the replies, but seem to me that I don't explain myselft well and replies are not related to my questions. So, lets put this question in verbose mode Wink

view/viewfile.php:
Code:
<html>
    <body>
      <h1> My name is:&lt;?php echo $name?&gt;</h1>
    &lt;/body&gt;
&lt;/html&gt;


controller/controllerfile.php
Code:
class Controllerfile extends CI_Controller {

    public function index()
    {
        $data = array ('name' => 'Frank');
        $this->load->view('viewfile', $data);
    }
}

That is the normal CI workflow but what I want is something like:

controller/controllerfile.php
Code:
class Controllerfile extends CI_Controller {

    public function index()
    {
        $data = array ('name' => 'Frank');
        $viewContent = '&lt;html&gt;&lt;body><h1> My name is:&lt;?php echo $name?&gt;</h1>&lt;/body&gt;&lt;/html>';
        $this->load->SOME_FUNCTION_OR_WHATEVER($viewContent, $data);
    }
}

so, what I need is pass the view content to the "load->view" function as a var instead of a file name, my goal is kind of allow users define view content and store into the database, not in the file system.

Thanks for your patience.
Frank
#6

[eluser]CroNiX[/eluser]
Read the link in my post. It tells how to do exactly what you are asking....set a string as the output. You don't use "load" for this... load loads files.

#7

[eluser]frankabel[/eluser]
Thanks again. I read the link first time you sent it but I don't get it Sad

If you are refering to:

Code:
$this->output->set_output($data);

well, I really don't know what
Code:
$data
is, speaking in the context of my example, I don't know if
Code:
$data
var is
Code:
'&lt;html&gt;&lt;body><h1> My name is:&lt;?php echo $name?&gt;</h1>&lt;/body&gt;&lt;/html>'
or what? in case that is the template content, where I specify the place holders values?, I mean, when I put
Code:
echo $name
, where the value of $name var come from if I don't pass it?




Theme © iAndrew 2016 - Forum software by © MyBB