I'm building a component for Joomla! 2.5 and inside I'm using JRoute::_('index.php?option=com_myapp&view=cpanel') to build all my links. This works, BUT it produces links which look like that:
/component/myapp/cpanel.html
In the menu however I have defined that index.php?option=com_myapp&view=cpanel has an alias of "myapp" so the link should rather be
/myapp/cpanel.html
The component is accessible via this path. If I do that, also all links generated inside will have the /myapp prefix. But for use in a template (special login link) and if the user stumbles upon /component/myapp.... I still want all links to go to /myapp prefix.
How can I force JRoute to use this menu item entry by itself?
Because I struggled a lot with this issue, here's a quick function I did that will try to find the link based on a menu item. It's mainly based on other answers.
This has only been tested on Joomla 3.5. JRequest is deprecated, so $app->input is used instead. This might be done better, but at least it works for the use I have of it. Hopes it can help other people too !
public static function getRouteMenu($default_url) {
$db = JFactory::getDbo();
$app = JFactory::getApplication();
$jinput = $app->input;
$db->setQuery('SELECT `id` FROM #__menu WHERE `link` LIKE '. $db->Quote($default_url) .' AND `published` = 1 LIMIT 1' );
$itemId = $db->loadResult();
if($itemId) {
$route = $jinput->getString('return', JRoute::_('index.php?Itemid='.$itemId));
$route = str_replace('index.php/', '', $route);
} else {
$route = $jinput->getString('return', JRoute::_($default_url));
}
return $route;
}
The parameter requires a not rewrited link such as : index.php?option=com_content&view=article&id=10. Check your database if you need to be sure about how to build up this link.
//look if there is a menu item set for myapp. if yes, we use that one to redirect
$db = JFactory::getDBO();
$defaultRedirect = 'index.php?option=com_myapp&view=cpanel';
$db->setQuery('SELECT `id` FROM #__menu WHERE `link` LIKE '. $db->Quote($defaultRedirect) .' LIMIT 1' );
$itemId = ($db->getErrorNum())? 0 : intval($db->loadResult());
if($itemId){
$rpath = JRequest::getString('return', base64_encode(JRoute::_('index.php?Itemid='.$itemId)));
}else{
$rpath = JRequest::getString('return', base64_encode(JRoute::_('index.php?option=com_myapp&view=cpanel')));
}
Beware: This is NOT language-safe. It takes the first menu entry found in the db. If you setup different menu aliases for different languages you have to check for the right language in the SQL query, too.
You ideally need to set a router as part of your component. The menu manager will override the component/myapp bit, but what comes after that will be determined by what is in the router.php file.
http://docs.joomla.org/Supporting_SEF_URLs_in_your_component
If, however, you simply need to create a link to a specific menu item, then you can always just add an Itemid to your parameter
JRoute::_('index.php?Itemid=12')
will point to any menu item with the id 12, so if that is your menu item ID for your com_myapp component, it will create the menu version of the link to that page.
edit:
You could technically assign the same component to two menu items, so I don't believe that handling the beginning of the URL is default behaviour when you link to a component outside of a menu item without giving the link an itemid. Joomla say (on creating a link for JRoute)...
"Notice that it is possible to leave out the parameters option and
Itemid. option defaults to the name of the component currently being
executed, and Itemid defaults to the current menu item's ID."
ie, call it from your homepage (or any page outside of one set to use your component) without an itemid or option and it is likely to think you are in com_content and with the homepage menu item.
If you want to link to the component outside of a menu item but without hard-coding an itemid, then one way would be to add a Menuitem field type to the config options of the module or template where you are linking from, and then add the itemid it generates to your link.
You could also use JFactory::getApplication()->getMenu() to find which menu item is linking to your component. Not had chance to test this - but using that could also mean that you can set an itemid parameter in your router.
Related
I've created a module for Joomla that fetches some data from a database and creates a table with it. I added JPagination to my module and I got the footer buttons to show and everything.
public function addPagination($params)
{
$count = $params->get("count");
$multiPage = $params->get("multiple_pages");
//Add controls for changing pages
if($multiPage)
{
jimport('joomla.html.pagination');
$limitStart = 0;
$pagination = new JPagination(count($this->vacanciesRows) , $limitStart, $count);
echo $pagination->getListFooter();
}
}
but when I click some of the pages (all except the first one) I'm getting error 404. I'm sure I've missed something but I have very little to none experience with Joomla. I'll include pastebins with my helper.php and my mod_xxx_xxx.php
A module can't have a pagination. It has no own URL. Only components have that. If you check the links your module creates, you'll notice that they are invalid. You can try to do Ajax magic but then you need a component providing the data.
In Joomla only components can react to incoming URLs directly.
Previously I've worked out how to hardcode content areas and the autonav block into my templates. I'm trying to do the same for a page_list which displays pages with a certain page type news entry, using pagination and just showing the title.
Here's how far I got:
<?php
$archive = BlockType::getByHandle("page_list");
$archive->controller->orderBy = "chrono_desc";
$archive->controller->ctID = "news";
$archive->controller->paginate = true;
$archive->render("view");
?>
But this doesn't seem to display any pages on the site. What have I done wrong?
It looks like you're supplying a page type handle instead of an page type ID to ctID.
You should be able to do something like so:
$sweetPageType = PageType::getByHandle('news');
if(is_object($sweetPageType)) { // let's be extra safe, eh?
$sweetPageTypeID = $sweetPageType->getPageTypeID();
}
And then, in your hardcoded block (you could test that you have an ID, although I think if it's null it would just have no effect):
$archive->controller->ctID = $sweetpageTypeID;
Dunno if you're using 5.6 or 5.7 but I believe it should be the same for both. Here's a relevant link to the c5 API:
http://concrete5.org/api/class-Concrete.Core.Page.Type.Type.html
Good day all.
I'm developing a simple module for prestashop, the idea is to be able to setup the hreflang thing in the backoffice, and inject the code in the header of all the pages. I'm actually struck at this point:
let say I'm on a page which URL is:
http://www.server.com/en/content/8-quality
from here, I want to retrieve the URL of the same page, let's say in italian:
http://www.server.com/it/content/8-qualita
is there a way to do it without try to search this on the database? I mean, this should be work for cms pages, products, categories and so on, I would like a way to ask Prestashop:
which is the URL of the current page in a given langage?
thanks in advance.
Assuming the page you want is a cms one, in the Link.php class, you have the following function :
public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null)
Juste call it with the good lang id and it's done. You can call it from smarty with
{$link->getCMSLink('quality', null, false, $id_lang)}
I have some questions concering routing with Codeigniter. What I´m doing now is the following:
$route['articles/(:num)'] = 'articles/view/$1'; // $1 will contain an ID
This means that example.com/articles/123 will work perfectly and load an article with an ID of 123. But I also want to have the possiblilty to add the aticle´s title to the URL (for SEO). Example: example.com/articles/123/article-title
What I want is pretty much the same thing as Stack Overflow: stackoverflow.com/questions/123/the-title
How can I do that?
I´m also wondering how Stack Overflow works. If I go to stackoverflow/questions/111 the title will automatically be added to the url. Is that done with php redirect()?
I have done something similar in the past; I can't find it know but IIRC (it was months ago) You can use a route like you did, and also add a more specific one, like
$route['articles/(:num)/(:any)'] = 'articles/view/$1/$2';
$route['articles/(:num)'] = 'articles/view/$1';
As you can see, both map to the same method, which is kind of "overloaded"; you can make up for a missing parameter by using a default value:
function articles($id,$slug = FALSE)
{ }
and simply ignore the second parameter in your article retrieval.
As for adding the title you can:
have a "slug" field in your database, created when the article is saved. You can use the comfortable url_title($title,'dash',TRUE) function (in the url helper), which takes the $title, uses the dash as separator, and make it all lowercase;
use the above function and convert the title of the article (after you retrieved it from the database) "on-the-fly"; just check on the article() method if the 2nd parameter isn't false and you'll know if you need to create the slug or not;
As for how to show the slug even when using an url without it you can make, as you guessed, a redirect, but since both routes point to the same method it won't change anything for you.
Oh, uhm, beware of loops while calling the redirect, check carefully ;)
I suggest you to create a slug field into your table and complete it with the url you want to use as id.
Let me explain.
You have this table
id
title
slug
when you save an article into your db you can dinamically create a slug, for example:
id: 1
title: My first post
slug: 1-my-first-post
then you can use the slug (in this case 1-my-first-post) ad id for the page, you can call it:
www.example.com/articles/1-my-first-post
obviusly you need to handle it in your db slect
As we discussed on the comments.
You can create a route several times and with different parameters each, like:
$route['articles/(:num)/(:any)']
$route['articles/(:num)']
I would create a function with a redirect, adding or not the title to it.
Hope it helps.
Can I set the default in phpMyAdmin to open in structure instead of browse?
thanks
If perchance you are using the "quick access icon" next to the table name in the navigation frame, this may be configured.
From the configuration file documentation:
$cfg['LeftDefaultTabTable'] string
Defines the tab displayed by default when clicking the small icon
next to each table name in the
navigation panel. Possible values:
"tbl_structure.php", "tbl_sql.php",
"tbl_select.php", "tbl_change.php" or
"sql.php".
For MAMP 3.x the DefaultTabTable configuration parameter applies. It needs to be set in MAMP/bin/phpMyAdmin/config.inc.php, e.g.:
$cfg['DefaultTabTable'] = 'sql.php';
As I said in my comment, you can click on the little table icon to the left of the table name (assuming, as Mike B said, we are talking about the table list on the left) and it will open up the table structure page.
AFAIK, switching the behavior on those links is not possible through a configuration directive. You would have to dig through the code and change it in there. Shouldn't be too complicated, though.
Add:
$cfg['DefaultTabTable'] = 'tbl_structure.php';
To either config.inc.php or config.default.php.
You can also change LeftDefaultTabTable which changes the icon. The options are:
'tbl_structure.php' = fields list
'tbl_sql.php' = SQL form
'tbl_select.php' = search page
'tbl_change.php' = insert row page
'sql.php' = browse page
In phpMyAdmin 4.8.2...
Click the double gears icon at the top of the left navigation pane.
Then click the "Tables" tab within the popup modal. (last tab)
There you can set the "Target for quick access icon" setting, which is referring to the little index card icon to the left of the table links in the left pane.
I didn't see any settings to change the default link behavior, but you can also add an additional "Target for second quick access icon" and define it's default view behavior differently if desired. It adds an additional "Quick access" icon to the left of the table links with your chosen behavior.
I use an old version of XAMPP (1.6.7) which contains an old version of phpMyAdmin (2.11.7), but the following worked for me.
In the /phpmyadmin/libraries/config.default.php file there is a section of code that handles how the table is viewed.
Change the last two lines of code to suit your purposes, for mine I wanted to open tables in "Browse" view, not "Structure" view (which was my default).
/**
* Possible values:
* 'tbl_structure.php' = fields list
* 'tbl_sql.php' = SQL form
* 'tbl_select.php' = select page
* 'tbl_change.php' = insert row page
* 'sql.php' = browse page
*
* #global string $cfg['DefaultTabTable']
*/
// Show table Structure - Default
$cfg['DefaultTabTable'] = 'tbl_structure.php';
// Uncomment below to show table data
// $cfg['DefaultTabTable'] = 'sql.php';
Save this config file and refresh PhpMyAdmin in your browser.
Hope that helps!
In version 3.5.1: go to the PhpMyAdmin home page -> Settings -> Navigation Frame -> Tables tab. Here you will find an option "Target for quick access icon", and set it
"sql.php" if you want it to go to the Browse tab
"tbl_structure.php" if you want it to go to the Structure tab
"tbl_sql.php" if you want it to go to the SQL tab
"tbl_select.php" if you want it to go to the Search tab
"tbl_change.php" if you want it to go to the Insert tab.
Then Save.
This way when you will click on the table name, it will go to the structure; and when clicking on the little icon before the table name, it will go to the tab you just set.
navigation.php
Around Line #646 in phpMyAdmin version 3.3.8
Insert
$href = $GLOBALS['cfg']['LeftDefaultTabTable'] . '?'
. $GLOBALS['common_url_query']
.'&table=' . urlencode($table['Name'])
.'&goto=' . $GLOBALS['cfg']['LeftDefaultTabTable'];
AFTER
$href = $GLOBALS['cfg']['DefaultTabTable'] . '?'
.$GLOBALS['common_url_query'] . '&table='
.urlencode($table['Name']) . '&pos=0';
to make the text field name link in the navigation to behave the same as the little icon to the left of it.
In my version, the configuration setting for it is supposed to be
$cfg['DefaultTabTable'] = 'tbl_structure.php';
It is listed in sample config file. However, /libraries/navigation/Nodes/Node_Table.class.php on line 34 ignores this setting and uses 'sql.php' directly. I changed that line to
'text' => $GLOBALS['cfg']['DefaultTabTable'].'?server=' . $GLOBALS['server']
On that line and it works fine for me.
Go to phpMyAdmin/config.inc.php
find line starting
$cfg['DefaultTabTable']
and set it to value
$cfg['DefaultTabTable'] = 'browse';
Restart Apache, empty session data (second icon under phpMyAdmin logo, alternatively log-out and log-in, not sure if this step is needed, some configs are cached in user's session)
This solved the issue in MAMP 5.7 (i.e. if you click on table name in left navigation tree, the Browse tab is open). PhpMyAdmin is located in MAMP/bin folder
I was following the instructions from etheros and wasn't able to find that configuration option, but it can just be added (to the confic.inc.php file). In my config file, I added it to the "Left frame setup" section, around line 160.
Depending on the phpMyAdmin version either of these should work:
$cfg['LeftDefaultTabTable'] = 'tbl_structure.php';
$cfg['NavigationTreeDefaultTabTable'] = 'tbl_structure.php';
Also you may actually be saving these setting in the phpmyadmin database, table=pma__userconfig. Go ot the phpmyadmin home and click Settings -> Navigation Frame ->Tables -> Target for quick access icon