Component Pagination for Joomla 2.5 - joomla

I am writing a new component for Joomla 2.5 and I am having problems wrapping my head around paginiation on the frontend(user site).
I have looked at the core component (com_content) to see how they do it and I am still unable to replicate the same. So when I put the line in my view.html.php file:
$pagination = $this->get('Pagination');
I get the JPagination Object and can print it out but I can not get them to display properly like below (how they do it in com_content)
echo $this->pagination->getPagesCounter();
echo $this->pagination->getPagesLinks();
What am I missing? What else do I need to have? Do I need to have more functions in my Models/thisview.php file?

Looks like you should be doing like so:
$pagination = $this->get('Pagination');
echo $pagination->getPagesCounter();

Related

Joomla 1.5 to 2.5 - how to get group names of component settings

I am upgrading a Joomla Website from 1.5 to 2.5 and I have a problem with a custom component which gets the setting params from the JEvents component. The old source tries to get the group names of these settings like this:
$groups = $this->params->getGroups();
But this does not work with Joomla 2.5.
I didn't find useful information on Google, so maybe you can help me out with this.
Thank you very much!
If it's simply the parameters from JEvents that you want to retrieve, then you can use the following:
$app = JFactory::getApplication('site');
$params = $app->getParams('com_events');
$var1 = $params->get('paramName1');
$var2 = $params->get('paramName2');
$var3 = $params->get('paramName3');
Hope this helps
Solved it by myself.
I changed the component input to a Form instead of Parameters and bound the Parameter Data in a JRegistry to the form.
The view works with fieldsets as groups.

how to debug opencart project ? for example putting break points step into code etc?

I'm new one to opencart.is there any debug tools available for opencart ? .i don't know control flow of opencart execution.so i want to put break points,step into code,see variable values. please give any reference to that .thanks in advance.
I wrote a super simple little function for the loader class that I use 100 times a day. It really helps and you can call it from just about anywhere.
OPEN:
system/engine/loader.php
Right before the closing brace for the class add this method:
// adding testing method
public function test ($items, $quit = true) {
echo "<pre>";
print_r ($items);
echo "</pre>";
if ($quit):
exit;
endif;
}
Now anytime after the Controller is instantiated you can call:
$this->load->test($results);
OR:
$this->load->test($results, false);
if you're in a loop and don't want the script to exit.
Obviously substitute $results for whatever array or variable you want to test.
It's been a huge help to me.
You can of course add this via vqmod if you don't want to modify the core.
You are right. Opencart is very simple system.
In addition you can use xDebug - very useful tool.
Also, read system/logs/error.txt
error_reporting(E_ALL); // very helpful
die(print_r($_POST, true)); // print all POST data and break the code
you can use https://github.com/mithereal/opencart_inline_debuggers and just d($var); in the source where var is a varible or object

Echo Joomla K2 Item Title in Main Template Using PHP

I'm trying to simply echo the title of the current k2 item I'm viewing, but the echo will not occur within the K2 template, it should show in my MAIN site template.
I tried this:
<?php echo $this->title; ?>
But that displays the FULL site title including my company name because I have it set that way in the main Joomla configuration.
I don't want the full site title that is generated for the 'title' tag in the head of the website; I just want to generate the name of the specific item I am currently viewing. This is probably pretty easy, but my PHP knowledge is limited.
I realise this is pretty old. However if you are still looking for a solution. This is not very elegant but will do what you want.
Firstly, just in case you weren't aware, you can get the article id from anywhere in by doing a JRequest:getVar('id') which will use a GET request to get the id from the URL.
$id = JRequest::getVar('id');
$id = explode(':',$id);
echo $id[0];
The reason I am exploding it is because in my site I am using aliases which if you are and you echo $id without you will see its in the form id:alias.
Using this method, you could query the database to get the name associated with that id in the k2_items table. You could create a function to do that which is else where in the templates folder then just assign it to a variable which you echo in the template. That keeps your template clean but gives you what you want.
Like I say, not a quick elegant solution but will work.

Joomla plugin : how to get article title and article id

I have developed on simple plugin in Joomla 1.6
I stuck at : How to get article title and article url.
I am getting no output if tried to print below statement:
echo $article->title;
echo $article->id;
I have written this in php file, not used MVC architecture.
Is there any other settings need to do in Joomla admin side ?
Please suggest your pointers for extracting article title and article url.
Thanks in advance!
Pravin
In order to get the article ID you have to write the following:
echo JRequest::getVar('id');
For the title, you just take the id you got, load the article object
$blabla = $article->load(ID);
echo $blabla->get('title');
It seems JRequest is deprecated in 2.5 & 3.x as indicated in the Deprecated Elements list.
I would rather use the following:
$article_id = JFactory::getApplication()->input->get('id');
i tried :
public function onContentPrepare($context,&$article, &$params, $limitstart) {
echo JRequest::getVar('id');
}
Still I am not getting the id. Is this right?
The article is loaded in your second argument ($article). Being on this event (onContentPrepare), the only property you can access is $article->text.
For suiting your purpose (getting the article id and title) you will want to use another event, called "onContentBeforeDisplay".
public function onContentBeforeDisplay($context, &$article, &$params, $limitstart)
Here you have (again) the article passed through the second argument, but now you have access to properties like $article->id, $article->title and many others.
For future references on content events, take a look at the file "plugins\content\example\example.php"
You can use for getting active article title like this
$menu =& Jsite::getMenu(); echo $menu->getActive()->title;
may this help.
To get Joomla article id use this...
<?php echo JRequest::getVar('Itemid'); ?>
In the previous answer someone used id instead of Itemid. Hope this helps!

Page-specific logic in Joomla

I am trying to enable JavaScript in a Joomla template to behave differently depending on the page. In particular, I have set the Key Reference as that appears to be the most appropriate value I could find for this purpose. Unfortunately, I can't seem to access it in my code. I tried:
$this->params->get("keyref")
and a few other variations, but they simply returned a blank. How can I retrieve this value or is there a better way of writing page specific logic.
Related Articles
Joomla load script in a specific page: This would work, but seems like overkill for what I want to do here.
Each page can be given an alias. We can retrieve the alias using code from the forum:
function getCurrentAlias()
{
$menu = &JSite::getMenu();
$active = $menu->getActive();
return $active->alias;
}
We can then inject this into the Javascript:
var alias= '<?php echo getCurrentAlias(); ?>';
I'm not aware of keyref, but I would solve it by using the class suffix parameter you can set for each menu entry.see I would use a space in front of this suffix. With javascript you can then try to read this classname (suffix without the space) on each page.
getElementsByClassName("mysuffix");
for example
If this returns multiple objects, you know on which page you are. Will that help you?

Resources