Load View into a Variable

Load view into a variable

It is possible:

$msg = $this->load->view('some_view', '', true);

Codeigniter - how to pass variable without load view

Try this

In Controller

function index(){
$data['myvar'] = 'test'
$this->load->view('homeview', $data);
}

In your homeview if you are laoding maincontentview then use below code

<?php
$MyData['myvar'] = $myvar;
$this->load->view('maincontentview', $MyData);
?>

Now you can use $myvar in your maincontentview also

How to load view in phalcon without any other contents

You need to disable rest of the view rendering. Example of exact situation (returning JSON response for AJAX)

$viewParams = [
'param1' => '....',
'param2' => '....',
];

$response = new \stdClass();
// Render view into a variable
$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);
$response->html = $this->view->getRender('yourTemplateDir', 'yourTemplateName', $viewParams, function($view) {
$view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
});

// Disable view
$this->view->disable();
return $this->response->setJsonContent($response);

How can I pass variable from a view to another view

If you mean, that you set a variable in one view, then you call an other view inside that view and you would like to use it there, the easiest way, to set it in the controller, which call the view.

$data['var'] = 'value';
$this->load->view('view file',$data);

Then you can reach that in every sub view.



Related Topics



Leave a reply



Submit