I am new in joomla, My code is like this
//on controller
function listing()
{
JRequest::setVar( 'view', 'hello' );
JRequest::setVar('hidemainmenu', 0);
parent::display();
}
//on view.html.php
i want to fetch this 'hidemainmenu'
How can i fetch can anyone help??
If the code above is that of your view.html.php file then you can pass the variable through to your template file by using a line like so:
$this->assignRef( 'hidemainmenu', $hidemainmenu);
Then in your tmpl/default.php file for example you can access this variable like so:
$this->hidemainmenu
If the code is in the Controller :
get the Variable in the view.html.php
as
$hidemainmenu = JRequest::getVar('hidemainmenu');
Try this in the view.html.php or default.php
Related
I want to call controller function in view page.
Here is function code :
public function annulerSeanceConduite(Request $request,SeanceConduite $seanceConduite)
{
//
$seanceConduite->statut = "Annulée";
$seanceConduite->save();
$request->session()->flash('message', 'Seance Conduite est annulée!');
return redirect('seanceConduites');
}
And the route :
Route::get('annulerSeanceConduite', 'SeanceConduiteController#annulerSeanceConduite');
You can assign name to your Route when you define it and use that name to generate the correct URL in your view file
Route::get('/annulerSeance/{id}', 'SeanceConduiteController#annulerSeanceConduite')
->name('annulerSeance');
and in your view file you use it like this
Annuler
Instead of a button, you could use a normal "a", or bind the link the the specified route to an onclick event on the button.
I have a problem understanding how variables work inside the Laravel templating system, Blade.
I set the variables in the controller, I can see them in the first view I make, but not inside the next one.
I'm using a master.blade.php file that holds the header and footer of the page, yielding the content in the middle. I can use the variable inside the master.blade.php file, but not inside the content blade file (variable undefined).
For example, for the contact page:
CONTROLLER FUNCTION:
$this->data['page'] = "contact";
$this->layout->content = View::make('pages.contact');
$this->layout->with('data', $this->data);
MASTER.BLADE.PHP:
if ($data['page'] == 'contact')
{ //do something, it works }
#yield('content')
CONTACT.BLADE.PHP:
if ($data['page'] == 'contact')
{// do something. ErrorException Undefined variable: data}
Am I missing something or is it a known restriction?
Thanks!
The problem was that I was passing the variables only to the layout:
Instead of:
$this->layout->content = View::make('pages.contact');
$this->layout->with('data', $this->data);
I fixed it using:
$this->layout->content = View::make('pages.contact', array('data' => $this->data));
$this->layout->with('data', $this->data);
This way passing the variables to the layout, but also to that particular view.
Hope it helps someone.
I have a script that uploads to a folder and I want to display a view after the upload is done, successful or not.
/component
/admin/
/views/
/components/
view.html.php
/tmpl/
default.php
modal.php // I want to load and output this file from controller.php
component.php
controller.php
/site/
I would like to do something like this, in my controller
$view = $this->getView(/* params for modal.php to load*/); //get the view
$this->view->display();
thank you
Try using:
$view = $this->getView( 'components', 'html' );
$view->setLayout('modal');
$view->display();
or
JRequest::setVar('view', 'components');
JRequest::setVar('layout', 'modal');
is there any way to load a view (for header or footer) on every function (in a controller)? I have a couple of if/else statements there and it would be a pain to change it all when I'll need to.
Yes, you can load the view in the __construct function at the top of your controller. Take
a look at the PHP manual on Constructors
function __construct()
{
parent::__construct();
$this->load>-view('your_view');
}
If the header and footer are going to be constant and required components for the visual part of your site, but you may want to load a different content portion between your header and footer, then you can make a function that will take an argument.
private function doViews($argument)
{
$this->load->view('header');
$this->load->view($argument);
$this->load->view('footer');
return NULL;
}
You may want to have an array of available views inside the doViews function in order to do proper validation that the file exists. Then you simply call the function in each method in your controller like this:
$this->doViews('main_content');
You should try using a Template library like this: https://github.com/philsturgeon/codeigniter-template
Then all you need to is put this in the controller (can be in __construct or within a method)
$this->template->set_partial('header', 'layouts/header');
$this->template->set_partial('footer', 'layouts/footer');
$this->template->set_partial('sidebar', 'layouts/sidebar');
Then to send data like you do with a view:
$this->template->build('create', $this->data);
you could create your main_view ... as a master page that already has a structure:
main_view.php
$this->load>-view('header');
<?php //get content here
?>
$this->load>-view('footer');
If you want to change something in the header or footer (through a statement) you can add content:
function __construct()
{
parent::__construct();
$data['footer'] = ($a == 'foo') ? 'footer one' : 'footer two';
$data_to_main = $this->load->view('template/footer', $data, TRUE);
$data_to_main = 'others';
$this->load>-view('main_view', $data_to_main);
}
Basically, I want to use a php variavle in a external Js file by ajax. For instance:
in a example.php file
<?php
$a="123"
//and then I want to call a show() function through a onclick event later
<xxxxxxxxxxxxx...... onclick="show()">;
?>
in another example2.js file there is a function
show()
{
var b
// I want to assign $a's value to this variable b here.=> b=a
//but I only want to do this way by using ajax.
}
Is there anybody can tell me how to do that? Thanks.
did you try to insert the ajax_object.responceText into a value in a and then get it with javascript?