Where to Place Navigation in Joomla Component Development - joomla3.0

I am developing a component 'com_datamanager' with an "Admin Dashboard" using ElaAdmin HTML5 Admin Dashboard Template. I have been able to create a simple component with multiple views without the dashboard template and it works.
But now I am stuck at how to add the 'dashboard theme' and which section whether in the view.html.php or tmpl/default to place all the "sidebar navigation"
The navigation will hold a link to all the various views of the component such as create, edit, delete, messages, product details, product list etc and it must also appear on all the above mentioned views.
I will be glad if someone can help me. thank you

Follow below steps
Create helper file of component if you it is not already there and paste below code in your helper file of component. If file is already there only past function part.
class MyComponentHelper
{
public static function addSubmenu($vName = "")
{
JHtmlSidebar::addEntry(
JText::_('Product List'),
'index.php?option=com_mycomponent&view=products',
$vName == 'products'
);
JHtmlSidebar::addEntry(
JText::_('Product'),
'index.php?option=com_mycomponent&view=product',
$vName == 'product'
);
}
}
Now go to yours views/dashboard's view.html.php file and paste below code before the display method call.
MyComponentHelper::addSubmenu('products');
Same code snippet will go in the product view also just change the view
Let me know if you face difficulties in this. It would be more help full if you post components file structure here.

Related

Angular2 router.redirect in component is loading the component. But http data population in view is delaying for more than 10 seconds

In my Angular application,I am having a controller for category.
In which (It has to check weather the customer is selected or not.If not it has to redirect to customer view page.
Working fine.(But when redirecting to customer page -customer list is populating in component constructor -not loading in view page)
After few seconds(almost 10-15 )seconds.
It is loading in View Page.
But if i open customer page by clicking the menu.(data loading is Fine).Why is this issue occurring
I have used some jquery inside typsecript for click functions and so.
I will post my code along with this please verify and help me.
Thank you.
constructor(private sidepageadd:SidePageAddService, private router:Router ,private zone:NgZone)
{
this.category_id=this.sidepageadd.getcategory_id();
this.categoryName=sidepageadd.getcategoryName();
this.customer_id=this.sidepageadd.getcustomer_id();
this.employee_id=this.sidepageadd.getemployee_id();
if(this.customer_id==undefined){
toastr["error"]("Kindly Choose a customer to Begin with!");
this.router.navigate( ['/home', {outlets: {'menu': 'home/viewCustomer'}}]);
}
else if(this.category_id==undefined){
alert("Choose a category");
}
var catName=this.categoryName;
if($('#catName').text()!=catName){
$('#catName').text(catName);
}
}
and after view seconds view is populating like this
I had similar issue before,
i used jquery for DOM manipulation
learn to use viewchild, Renderer,Elementref etc and use queryselector for manipulating dom inside typescript code.
Go through this link:
https://blog.angularindepth.com/exploring-angular-dom-abstractions-80b3ebcfc02
(I learned from here)
I guess this will help you.

CakePHP 2.5.2 Themeing and theme.ctp

I've created a simple application that is about to be vastly expanded upon and get a bit out of hand if I don't get the theme sorted out early as I need to start working with tinyMCE.
I created my theme in app/View/Themed/Default and added the following into my app controller
public $theme = 'Default';
Something seems to be working because cakePHP is not rendering my views and is giving me the following errors.
Error: The view for {controller name}Controller::add() was not found.
Error: Confirm you have created the file:
/home/cake/public_html/app/View/Themed/Default/{controller}/theme.ctp
I've been reading through the documentation and nowhere in there does it tell me that I need to create a folder for every controller and add a theme.ctp file inside. so I'm at a bit of a loss as to what needs to go into this theme.ctp file.
If I add the Controller folder, and a blank them.ctp file, the view is not rendered. So I am assuming something vital is required here.
I discovered the problem.
Further down the page from legacy code that was ported across, the following code was sitting at the bottom of the page.
AppController.php
function beforeRender() {
$this->view = "Theme";
$this->theme = "default";
}
So it was being forced into rendering a view that did not exist.

CakePHP - can't create more than one method (admin_index) in plugin

I'm a newbie in CakePHP, please have patience with me :)
So, I'm trying to create a plugin called References. I've baked "plugin's core" through cake's console. Then I've created ReferencesController class that extends ReferencesAppController and Reference class (model) that extends ReferencesAppModel. My next step was creating action admin_index (just code to save form), it's view and a little bit validation in Reference model. To my problem, I'm unable to create any other action, ex. admin_add. When I do (I create new action and I add it's view), then I try to access it through the URL (localhost/my_project/admin/references/add), and there comes the message "Error: References.AddController could not be found.". I am not sure, what I do wrong, I don't want to create another controller, just action. Thank you
Because only the plugin index action (when plugin and controller have the same name) is directly routed.
For all others you need to verbosly add the plugin name and the controller name to the url:
/my_project/admin/references/references/add
If you had created a link to this action, the routing would have shown you that.

CakePHP: Reusable content blocks and MVC

I'm trying to learn CakePHP by building a simple CMS app, it was going well but as I'm adding more, I'm getting a bit confused by the MVC structure.
In addition to my Posts, I have created a simple model for 'Content Blocks' (basically an admin editable title and content field) that I want to display as elements within other pages of my site.
To help explain:
My Posts controller has an index action that lists out all of the blog posts. In the view for that action I also want to pull a specific 'content block' from the database and display it at the top of the page.
Another example would be an admin-editable 'about' blurb that appears in the footer of every page.
Lastly, in a similar fashion to the Wordpress text widget or Magento static block, I'd like to prevent 'content blocks' being directly accessible (i.e. domain.com/content_blocks/view/id)
What is the ideal way to achieve this whilst staying true to CakePHP and MVC convention?
I've had several stabs at it (such as using requestAction in an element) but have only succeeded in getting more confused.
The way I would do it is as you suggested with a request action inside an element because that won't be directly accessible through the URL. So you would create a view inside the elements folder:
app/View/Elements/block.ctp:
<?php $sidebar = $this->requestAction(array(
'controller' => 'ContentBlocks',
'action'=> 'viewBlock',
'yourtitle'
));
// layout your block here
?>
app/Controller/ContentBlocksController.php
public function viewBlock($title) {
return $this->ContentBlock->findByTitle($title);
}
Then you can see this post for how to do caching with the element and requestAction: http://mark-story.com/posts/view/how-using-requestaction-increased-performance-on-my-site
Also, you might want to checkout Croogo, which has a lot of the functionality you are looking for and more already built in: http://croogo.org/

Custom Button or Link to a Visualforce page with a custom controller

I have a Visualforce page using a custom controller that is used to edit multiple records under an opportunity.
I'd like to create a custom button or link from Opportunities to this Visualforce page.
Currently the link looks like:
/apex/ExamplePage?oppId={!Opportunity.Id}
This works fine in the development sandbox, but when it is deployed as part of a managed package the link breaks as the page reference doesn't have the namespace prefix.
I found the post Managed Package Redirecting Problem on the Force.com Discussion Boards which implied it should be possible to use $Page to reference the Visualforce page in the URL. E.g.
{!URLFOR($Page.MyExamplePage,'',[objectId = campaign.id])}
But doing so only gives me the syntax error:
Error: Field $Page.MyExamplePage does not exist. Check spelling.
There is another part to the post that suggests using an Apex class and Execute Javascript to work around it. But it appears to me that this has just moved the namespace issue into the Javascript.
How can I safely reference the Visualforce page to work both inside and outside a managed package?
Best to do this from an Apex PageReference return value. Something like this will work:
public PageReference returnPage()
{
return Page.MyExamplePage;
}
Then call this from Visualforce:
<apex:commandButton value="Go To New Page" action="{!returnPage}"/>
The Apex Page call will handle the translation for you.
[EDIT]
Create a bare bones Visualforce page like this:
<apex:page standardController="Opportunity" extensions="TheController" action="{!returnPage}"/>
Add the above returnPage() method to a new TheController (or whatever) class. It doesn't even need a constructor. The class can look like this:
public TheController
{
public PageReference returnPage()
{
return Page.MyExamplePage;
}
}
Then from the Opportunity settings page go to Buttons and Links and create a new custom Visualforce button selecting the new page you just created.
That should do it.
It occurred to me that one less than ideal option would be to create two custom buttons in each case. One with the managed package namespace and one without.
When building the package the correct custom button could be selected.
One issue with this approach is the need to maintain two custom buttons.
It seems the answer is simply /apex/package__Page as provided here by #zachelrath. I can confirm this works in managed packages in production orgs as well as in development.
The post on the developer boards that you've linked to shows the following javascript being used for the button:
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var pageUrl = sforce.apex.execute("mynamespace.PageUrl", "getPageUrl", {objectId:"{!Campaign.Id}"});
window.location.href = pageUrl;
i.e. they're using javascript to call a webservice method in the class they've defined in order to get the page reference. Doing this would allow you to get the URL of the page in apex, where the managed package won't play an impacting part.
That said, the first parameter is the fully-qualified class name, so you could probably check the return value for an error (I don't know the error return value, so I'm assuming it's null here):
// try the namespace first
var pageUrl = sforce.apex.execute("mynamespace.myClass", "getPageUrl", {objectId:"{!Campaign.Id}"});
if (pageUrl == null)
{
pageUrl = sforce.apex.execute("myClass", "getPageUrl", {objectId:"{!Campaign.Id}"});
}
window.location.href = pageUrl;
Obviously you need to check what happens when sforce.apex.execute() fails, and you'll likely want some more error handling.

Resources