Custom component view to menu items in admin area?

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
devlabs
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Fri Jan 23, 2009 10:39 pm

Custom component view to menu items in admin area?

Postby devlabs » Tue Apr 27, 2010 12:49 pm

Image

How to add Custom component view to menu items in admin area?
I can see there only main component view, and need a link to additional.

devlabs
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Fri Jan 23, 2009 10:39 pm

Re: Custom component view to menu items in admin area?

Postby devlabs » Fri Apr 30, 2010 6:04 pm

the problem is that joomla doesn't allow "_" in the name of view folders, this is view view folders with "_" aren't shown in the menu list.

User avatar
Presto-X
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 241
Joined: Fri Apr 06, 2007 12:23 am
Location: Boise, ID
Contact:

Re: Custom component view to menu items in admin area?

Postby Presto-X » Fri May 07, 2010 4:26 am

Hey devlabs,

Open your controller.php file in your component folder
Look for something like this:

Code: Select all

if(JRequest::getCmd('view') == '') {
   JRequest::setVar('view', 'default');
}
Then just after that before for

Code: Select all

parent::display();
Add

Code: Select all

if(JRequest::getCmd('view') == 'add') {
            JRequest::setVar('view', 'YOUR_NEW_VIEW');
        }
Now go to your components views folder and add a new folder call it what you want your view to be. Create a new file in here called view.html.php

Code: Select all

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

/**
 * Change the name of DealerlocatorViewAdd to what you have in your controller for the call class YOUR_CONTROLLER_NAMEController extends JController { and replace Add on the end with your view name
 */
class DealerlocatorViewAdd extends JView {
   function display($tpl = null) {
        parent::display($tpl);
    }
}
Now create a new folder in your new view folder called tmpl then create a new file called default.php this will hold the code for this view.

User avatar
Presto-X
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 241
Joined: Fri Apr 06, 2007 12:23 am
Location: Boise, ID
Contact:

Re: Custom component view to menu items in admin area?

Postby Presto-X » Fri May 07, 2010 4:27 am

PS. I use Joomla Component Creator http://www.notwebdesign.com/joomla-component-creator/ to build the foundation of my components to save time, check it out.

PSS. take a look here for more info on component building: http://docs.joomla.org/Developers#Components

devlabs
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Fri Jan 23, 2009 10:39 pm

Re: Custom component view to menu items in admin area?

Postby devlabs » Fri May 07, 2010 8:33 am

Thanks, but the problem was in the "_" sign in the name of view folder, Irenamed it and everything works fine.

User avatar
Presto-X
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 241
Joined: Fri Apr 06, 2007 12:23 am
Location: Boise, ID
Contact:

Re: Custom component view to menu items in admin area?

Postby Presto-X » Fri May 07, 2010 9:26 am

Ahh I misunderstood what you where looking for my bad :O)

ggerstein
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Fri Feb 10, 2012 7:27 pm

Re: Custom component view to menu items in admin area?

Postby ggerstein » Fri Feb 10, 2012 7:36 pm

Hey Presto-X

I was interested in an example you posted on the joomla forum regarding making menu item type appear in the new menu item form.


Code: Select all

Open your controller.php file in your component folder
Look for something like this:
Code:
if(JRequest::getCmd('view') == '') {
   JRequest::setVar('view', 'default');
}
Then just after that before for
Code:
parent::display();
Add
Code:
if(JRequest::getCmd('view') == 'add') {
            JRequest::setVar('view', 'YOUR_NEW_VIEW');
        }
Now go to your components views folder and add a new folder call it what you want your view to be. Create a new file in here called view.html.php
Code:
// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

/**
 * Change the name of DealerlocatorViewAdd to what you have in your controller for the call class YOUR_CONTROLLER_NAMEController extends JController { and replace Add on the end with your view name
 */
class DealerlocatorViewAdd extends JView {
   function display($tpl = null) {
        parent::display($tpl);
    }
}
Now create a new folder in your new view folder called tmpl then create a new file called default.php this will hold the code for this view.


What I don't understand here is the last part. You create the controller class

Code: Select all

YOUR_CONTROLLER_NAMEController extends JController{and replace Add on the end with your view name
 */
class DealerlocatorViewAdd extends JView {
   function display($tpl = null) {
        parent::display($tpl);
    }
}

what do you mean Add on the end with your view name? The class DealerlocatorAdd extends JView{} is in the view.html.php right? You mean just replace the word "Add" on the end of the View class name? I guess I am just trying to understand consistently in your example what the view name would be so I can understand what parameters are being passed. I am also just trying to understand where each code block resides.

Also this block of code:

Code: Select all

if(JRequest::getCmd('view') == 'add') {
            JRequest::setVar('view', 'YOUR_NEW_VIEW');
        }


What you are saying here is if the request has a view command with a value of add, this is the menu item form submitting a request to create a new menu item with a specific view? Is that understanding correct?

Thank you. ggerstein


Return to “Joomla! 1.5 Coding”

Who is online

Users browsing this forum: No registered users and 8 guests