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');
Related
I'm corrently develop webs application for selling products online by using Codeigniter and upgrade from Ci2.2.1 to CI3.0.
However I've meet an errors 404 Page Not Found when I enter domain name on url not yet called any controller by hoped default_controller will load instead of type my main controller.
Notes: It is working on Ci2.2.1 and it stop work when upgrade to CI3.0.
It is working if I type any characters or any Controller after domain name(http://localhost/Ecom3/sometroller) But it is coudn't call default_controller and keep empty or blank after domain (http://localhost/Ecom3/).
Errors log: ERROR - 2015-04-24 03:48:57 --> 404 Page Not Found: /index
Please check my webs structure below:
Main->Main_controller->MY_controller->CI_Controller
My purpose to make it easy to controller the templates.
In MY_controller I've use __autoload() function
function __autoload($class){
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'libraries/' . $class .'.php'))
{
include_once $file;
}
}
}
And I have confige route as below
$route['default_controller'] = "main/Main";
$route['(:any)'] = 'main/main/index/$1';
$route['c'] = 'cat/cat/index/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
The problem:
My url can't be blank after I type domain or after forword slash as below image
Please help
I try your code and get 404 when Main.php in your controller place inside controller/main folder. but when im move Main.php into controller folder, default controller to Main has working. then im try to debuging and see:
// Is the method being specified?
if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
{
$method = 'index';
}
in core/Router.php
thats mean codeigniter3 are not allowed you to set default_controller in sub folder. you must put default_controller in app/controller/ to make it works.
in config/router.php
change this:
$route['default_controller'] = "main/Main";
TO:
$route['default_controller'] = "Main";
then move your controller file :
app/controller/main/Main.php
TO
app/controller/Main.php
I'm going through the Joomla 2.5 tutorial to build a custom component. Now I'm facing an issue on the redirection after using JToolbar::save() or JToolBarHelper::cancel for that matter. By default Joomla wants to redirect to the default layout (from the edit layout). However I don't want it to do that. I want it to redirect back to another view. In Joomla 1.5 I would have done this through adding the function into the controller - something like
function cancel()
{
//redirects user back to blog homepage with Cancellation Message
$msg = JText::_( 'COM_BLOG_POST_CANCELLED' );
$this->setRedirect( 'index.php?option=com_jjblog&view=jjblog', $msg );
}
Now that works beautifully for the cancel function, however for save this is a much more complex thing. If I want to overwrite the url do I have to redirect the controller to the model and then write in all the code for the model interaction? Because that seems slightly excessive just for a url redirection like you would in Joomla 1.5?
Hope you have added the save toolbar code with the proper controller name like this
JToolBarHelper::save('controllerName.save');
Create a save function in appropriate controller.
Add the task in the form
Finnally make sure you have added form action withthe corresponding component name.
You can try this-
In the controller firstly you call the parent save function than redirect to url.
function save(){
parent::save();
$this->setredirect('index.php?option=com_mycomponent');
}
OK it didn't need to $this->setRedirect at all. Just needed me to change the value to
protected $view_list = 'jjBlog';
which then sets the redirects of everything back to that list view.
Source link for this is here.
Thanks for all the responses though!!
view.html.php
protected function addToolbar ()
{
JRequest::setVar ('hidemainmenu', false);
JToolBarHelper::title (JText::_ ('Configuration'), 'configuration.gif');
JToolBarHelper::save($task = 'save', $alt = 'JTOOLBAR_SAVE');
}
controller.php
public function save()
{
$mainframe = JFactory::getApplication();
$mainframe->enqueueMessage (JText::_ ('COM_SOCIALLOGIN_SETTING_SAVED'));
$this->setRedirect (JRoute::_ ('index.php', false));
}
I think you can use
global $mainframe;
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
If you are overriding joomla's default save function in your custom component like
function save( $task = 'CustomSave', $alt = 'Save' ) // or even same name Save
Inside your controller you can use the CustomSave as the task and use $mainframe for redirect.
or
$mainframe = &JFactory::getApplication();
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
Hope this may help you..
I have simple line, but it doesn't work.
$this->getView($input->get('my_wiew', 'Sites', 'CMD'), 'HTML');
//some code
parent::display();
If i simple go to the url index.php?option=com_my_component&view=sites i get my view, but by default it doesn't want to load.
$view = $this->getView('view_name', 'html'); //get the view
$view->assignRef('data', $data_from_model); // assign data from the model
$view->display(); // display the view
Read more
Ive been working with CI and I saw on the website of CI you can load a view as a variable part of the data you send to the "main" view, so, according the site (that says a lot of things, and many are not like they say ...ej pagination and others) i did something like this
$data['menu'] = $this->load->view('menu');
$this->load->view ('home',data);
the result of this is that I get an echo of the menu in the top of the site (before starts my body and all) and where should be its nothing, like if were printed before everything... I have no idea honestly of this problem, did anybody had the same problem before?
Two ways of doing this:
Load it in advance (like you're doing) and pass to the other view
<?php
// the "TRUE" argument tells it to return the content, rather than display it immediately
$data['menu'] = $this->load->view('menu', NULL, TRUE);
$this->load->view ('home', $data);
Load a view "from within" a view:
<?php
// put this in the controller
$this->load->view('home');
// put this in /application/views/home.php
$this->view('menu');
echo 'Other home content';
Create a helper function
function loadView($view,$data = null){
$CI = get_instance();
return $CI->load->view($view,$data);
}
Load the helper in the controller, then use the function in your view to load another one.
<?php
...
echo loadView('secondView',$data); // $data array
...
?>
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