call controller to view i use this code..
i want to add "template/home/home" page in to iframe tag while calling controller to view.
how can i do?
class main_con extends Controller
{
function main_con()
{
parent::Controller();
// $this->freakauth_light->check('user');
$this->_container = $this->config->item('FAL_template_dir') . 'template/container';
$this->load->library('FAL_front', 'fal_front');
}
function index()
{
$data['redirect_page'] = 'template/home/home';
$this->load->vars($data);
$this->load->view($this->_container);
}
}
thank you in advance...
I'm not quite sure if I understand your problem but:
The iframe is in your view template right? So what you need to do is just print the content of your variable in the src attrib of the iframe.
Related
I have a project that needs to render data from the controller before pass to view on every page
Ex. controller --data--> {do something} --> view.blade
I tried middleware, but it's not working, because it ??? before the controller.
Does anyone know how to achieve this?
You might want to use the render method from a Illuminate\View\View object:
class QuestionsController
{
public function show(Question $question)
{
$content = view('questions.show', compact('question'))->render();
// Do something with the $content string.
}
}
My boss told me make dry navigation dont use repetitive code, for navigation i am trying to extend CI_Controler and with construct load header nav, body, footer files.
My question is when i create new controller and when i try to load different view files, how to achive that???
my extended controler
class MY_Controller extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->view('view_header');
$this->load->view('includes/nav_home');
$this->load->view('view_home');
$this->load->view('view_footer');
}
}
and later when i am creating new controler how to load diffrent view files
class Pages extends MY_Controller
{
public function __construct() {
$this->load->view('includes/nav_new_view');
$
}
}
You can create a template library yourself. For example :
function template($view_name,$view_data){
//below will return html string from view name
$data['content'] = $this->load->view($view_name,$view_data,true)
//load main template view and pass the html string to main template
$this->load->view('main_template',$data);
}
In main template, just echo $content
If I understand your question, you're trying to achieve a template situation. For this, the best way is to actually call your templates view files within a primary page view. What I mean is your controller function (not the constructor, an actual class function representing a page) should call a primary view such as
$this->load->view('page1', $this->data);
and within that file, you call
$this->load->view('nav', $this->data);
then your content and then
$this->load->view('footer', $this->data);
You would then repeat the process for page 2 where in your controller's page2 function, you would call
$this->load->view('page2', $this->data);
and your page2 view file is almost identical to page1 except you use your page 2 content in that area.
You could even use a single template view file and pass it a $content variable (which obviously changes per page) and call
$this->load->view('template', $this->data);
This is the function that I am using in my controller
public function homeList()
{
//Get all the franchises
$franchises = Franchise::all();
//Load the view and pass the franchises
return View::make('frontend.layouts.footer')->with('franchises', $franchises);
}
and I keep getting this error. I don't know how to pass it or what to put on the routes.php file
You should be able to do #include('frontend.layouts.footer')->with('franchises', Franchise::all()).
Update:
To avoid the model in the view, you should use a view composer, as it was stated in a previous answer.
View::composer('frontend.layouts.footer', function($view)
{
$view->with('franchises', Franchise::all());
});
Now you have $franchises available in the view. This code you can place in routes.php or you can create a composers.php and autoload it.
sorry for asking this question ..i am working on a Cakephp 2.x ... i have a view page in my controller name folder e.g Controller/index.ctp ... and i have ajaxfiles are stored in app/webroot/ajax/ajaxfile.html
now on my index.php file i am acessing the ajax page like this
<a href="ajax-demo/ajaxfile.html" class="file-link">
<span class="icon file-png"></span>
Simple gallery</a>
Controller
public function index(){
}
now the problem is i want to send the variables to both of my pages ... index.ctp and ajaxfile ... how can i do this ??what is the best approach to tackle these things ....
do i have to move the ajaxfiles from webroot and paste under the controller name folder?
if is it so then how can i send variables to ajax files which has no model and controller
please if any one know the solution then please advice me. and give an example too
There are different way to achieve this, here I'm writing the simplest one
First you need to move your "index.ctp" file to your "View/YOUR CONTROLLER NAME/" folder.
1) To access the variable in view you need to set it from your controller's method like this
public index(){
$this->set('yourVariable', 'Your Value');
}
2) To access the value in your view file (index.ctp), you need to call this variable like this
$yourVariable;//If you want to print this then you can write like this
echo $yourVariable;
3) To call a ajax file from your index.ctp the simplest method is to call a onclick event on this anchor, the onclick event will call a JAVASCRIPT method which will further make a ajax call and will place the output in an element in your index.ctp, The ajax call will further call your controller method (implement your html related logic here)
For example,
<span class="icon file-png"></span>Simple gallery
<div id="yourAjaxFileOutputReplaceMentDiv"></div>
4) create a javascript method in your JS file, this JS file must be loaded in your layout file.
function yourAjaxCallMethod(BaseURL,yourVarible)
{
//Initialize Ajax Method
var req = getXMLHTTP();//Let's this method Initialize your Ajax
if (req)
{
req.onreadystatechange = function() {
if (req.readyState == 4)
{
if (req.status == 200)
{
document.getElementById('yourAjaxFileOutputReplaceMentDiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
var URL = BaseURL+yourVarible+'/'+Math.random();
req.open("GET", URL, true);
req.send(null);
}
}
5) Your AJAX file related method in your controller "yourController". Set autoRender to False
public function ajaxMethod(){
$this->autoRender = false;
//Check $this->request['pass'] for arguments send from ajax call
$retreivedVariable = $this->request['pass'][0];
echo 'I retrieved variable'.$retreivedVariable;
}
However instead of writing core javascript and ajax method you can call the inbuild Ajax Helper for same.
just a quick question, Is it possible to call a cakePHP element via jQuery Ajax? I know the standard way to call an element in cakePHP is:
<?php echo $this->element('path_to_element', 'data_to_send_to_element'); ?>
But what if I wanna call my element inside the $.ajax or .load() function? How do I achieve this?
Thank you
To call anything in Cake, by Ajax or otherwise, you need to define an action in a controller. You could create a view too, but you can also have the action render an element directly by setting the viewPath. Example:
class MyController extends AppController {
// Apply Ajax layout automatically
var $components = array('RequestHandler');
function doSomething() {
$this->autoRender = false;
... // set parameters needed by the element...
// render an element
$this->viewPath = 'elements';
$this->render('path_to_element');
}
}