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
How to Allow Remote Access to My Wamp Server for Mobile(Android)
PHP Include(): File Size & Performance
How to Return Custom Error Message from Controller Method Validation
Return One Value from Database with MySQL PHP Pdo
Change Database Connection in Laravel Model
PHP & SQL Injection - Utf8 Poc
Laravel Error: Method Illuminate\View\View::_Tostring() Must Not Throw an Exception
How to Extract or Uncompress Gzip File Using PHP
What Does a PHP Function Return by Default
iOS Push Notification Does Not Work When Using Crontab Scheduler
Why Is Type Hinting Necessary in PHP
Answering Http_If_Modified_Since and Http_If_None_Match in PHP
Send a JSON Object from Android to PHP Server with Post Method and Httpurlconnection
Difference Between Require and Install VS Create-Project in Composer
How to Validate Phone Number Using PHP
One Form with Two Submit Buttons and Different Actions for Each Button