Broken links resulting from php include references - broken-links

I'm learning php but am up against a wall right now with a referencing issue. I've searched a lot but I can't find any posts with my exact structural problem. Hoping to master this hurdle so I can move toward the next...
My basic file structure something like:
domain.com/
home.php
images/
global/
nav/
nav-img.jpg
includes/
menu.php
fruit/
apples/
red/
gala/
gala.php
I want to create a global path establishing my web root directory that I can reference on the fly in each page wherever it resides. BUT other posts on this general topic give [10] different functions I can use. I just want [1]. Also, I don't know where to put [for example] define(ROOT), or how to call it from an individual page.
Will define(ROOT) work for my situation?
Knowing that all pages use [menu.php], my obstacle:
From gala/gala.php - when I click on [home], it looks for:
/fruit/apples/red/gala/home.php [does not exist, of course!]
Also, trying to AVOID these [2] things if possible:
I. Using html file references in gala.php like this: ../../../../includes/menu.php
to find the correct global include.
II. And avoid using link references in menu.php like this: /images/global/nav/nav-img.jpg
Any feedback would be appreciated [+] or [-]. Thanks a lot.

Ok, here's what I did that seemed the best:
For I. and II. to avoid using so many ../../../../
in all the src="" and href="" I just settled and used site-relative file references with leading slashes, such as "/includes/menu.php" which would get me to the site root, building the file's location from there.
For the global file reference, BOTH of these worked:
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/";
?>
// in `<head>` section
And using <?php include ('menu.php'); ?>
OR THIS ONE WORKED TOO:
<?php
define('ROOT',$_SERVER['DOCUMENT_ROOT']);
define('INCLUDES',ROOT.'/includes/');
?>
// in `<head>` section
And using <?php include (INCLUDES.'menu.php'); ?> in a file at another level.

Related

Prestashop 1.7 include inline SVG in tpl file

I am trying to include an SVG inside my tpl file like this :
<?php echo file_get_contents("icon.svg"); ?>
Do you have some idea ?
Finally, I found a trick to include inline SVG file using the template system.
So I just create a folder named _svg in the templates folder of the theme. I renamed my icon.svg file to icon.tpl and I included it using the following code:
{include file="_svg/icon.tpl"}
If you need a variable (for exemple in a loop, use :
{include file="_svg/icon-{$var.value}.tpl"}
If you have other ideas, do not hesitate to let me know !
See you!

Call module on needed page Opencart

How to call module in Opencart 2.0 using his "ID"? I need to view the some modules not different places, I try find solution in google but no luck.
Put this one in your controller.
$data['anyvar'] = $this->load->controller('module/your-module-id');
And in your view file just echo it. like,
<?php echo $anyvar; ?>

How to display modules only on search results in Joomla 2.5?

Hello please read the whole question, this isn't just solved by enabling the modules only for the search page:
I have a few modules that are exclusively shown on the search page in Joomla.
I created a hidden menu entry for the search as well in order to tell modules to only show on this page. This works alright, but when I click one of the results and get redirected to the actual result, then the modules, which should only show up on the search page are still shown in the result page.
Any clue how to fix this? Really annoying as I use 3rd party search enhancing modules, and they are showing on the results.
Using standard Joomla, there's no way to target modules to only the search results page and none of the pages that link off the results – but I know you knew that! The hidden menu item is a help, but does not change the menu item of some of the links off that page. It's all to do with the allocation and use of "Itemids" in Joomla.
To be able to target modules more specifically, you need to use a 3rd-party extension. I developed MetaMod (www.metamodpro.com) to cope with exactly this use case. MetaMod is a wrapper module that can then decide just which other module to include in itself (or not). So you assign the MetaMod to the page, then put a snippet of code inside the MetaMod which decides which other module to include.
In this case, I'd use the following in MetaMod:
if ($core_genius->check("pagetype = search, searchresults")) return XXX;
// replace XXX with the module id of the module to include
// ONLY on the search page, or the searchresults page, but
// no other type of page.
Hope that helps,
Stephen
Although MetaMod is great (I've used it myself & Stephen's support is great!) there is another way to do it without using 3rd party extensions.
You could create new module positions in your template above (or below) the module positions you wanted to use and wrap them in an if statement like so:
<?php if(!isset(JRequest::getString('searchword'))) : ?>
<jdoc:include type="modules" name="right-search" style="xhtml" />
<?php endif; ?>

Include Login Side Box which uses the Secure Module -- Play Framework

I'm working on this for days now and I just can't figure it out..
My question is: Is it possible to alter the login.html file in the view.secure folder, so that I could include it in another html-file with #{include 'views/login.html'}, let's say in the index.html, as a login-sidebox, and how could this work?
Move the code to a tag. Simply move the file "login.html" under tags folder, and then you can use it as:
#{login /}
That said, be careful. I don't have the code here but it may be that login is using some vars. If that's the case, you'll need to pas the vars to the tag and modify the tag slightly. For example, assume you have a var called "name" in the tag. You'll have to change "name" to "_name" in the tag and pass the var as parameter in the tag, as follows:
#{login name:name /}
This is the standard behavior of tags. You can check existing tags in the "samples" folder of the framework for more help.
Probably with #{extends 'index.html' /} combined with #{doLayout /} as shown in documentation.
With all of your friendly assistance i solved the problem!
I included the login-form into all sites i want it in, and when I get logged in or logged out, I use the onAuthenticated()/onDisconnected() to redirect to the wanted site!
But there is one problem left! If the case appears that a error message is displayed, like "User not existing" or something, it is not possible to handle that case.. it would be nice if you could also help me with that.

Htaccess Rewriterule virtual directories breaking all links

I think I've gone through a million articles and everyone's codes on this, but I just can't get it to work! Every code I try works but it shows the redirect url instead of the virtual one.
I would like mysite.com/company/client/ to actually show the results from mysite.com/company/client.php, but the files within client.php become broken unless I make absolute links.
For instance mysite.com/company/css/style.css is broken when viewing from http://mysite/company/client/, but is working fine when going to the real file mysite.com/company/client.php
I hope someone knows how to solve this problem without having to change all links in client.php to absolute!
Thanks!
Scott
You might want to consider the HTML BASE tag:
...
<head>
...
<base href="http://mysite/company" />
...
</head>
...
You put this in the client.php file, then any relative link & reference is automatically "converted" to an absolute one, starting from the right folder.
See the comments on possible issues with the BASE tag.
Another option would be to perform a redirect instead of a rewrite, by adding "[R]" to the RewriteRule. However, then your users will see the "client.php" in the URL.

Resources