I have a page with some HTML in it.
and I need to set the src property to the location of pictures.
How can I achieve that with Kohana PHP ?
Thanks.
It depends on where the images are located. In a standard Kohana install, the files are located in your document root and are accessible with the url::file() call, eg:
<?php echo url::file("images/foo.gif") ?>
would refer to:
http://example.com/images/foo.gif
Reference: http://docs.kohanaphp.com/helpers/url#file
Related
I would like to include several file in Magento 2 in one phtml file.
The project was in laravel at first and looks like this :
https://i.imgur.com/XpUbynf.png
So now I need to import all the project in a Magento 2 project but the semantic is different.
I have tried this so far but doesnt work :
https://i.imgur.com/hewweJg.png
The files I'm trying to call are in a subfolder and the path of these files is :
Wo/EyeTest/view/frontend/templates/eyetestSteps
with other subfolders like
Wo/EyeTest/view/frontend/templates/eyetestSteps/step1/
Wo/EyeTest/view/frontend/templates/eyetestSteps/step2/
Do you have any idea how can I do this ? When the file is in the same directory, there is no problem, it's display, and I guess I'm writting the path badly.
Thanks
Please use the below path for this:
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Wo_EyeTest::eyetestSteps/step1/_instructions.phtml")->toHtml(); ?>
I use Yii2 framework and I want to have a link in a php file called index.php to a pdf file called abc.pdf but the path that I wrote is not working:
I have these files:
my-project/backend/views/my-form/index.php
my-project/backend/views/my-form/abc.pdf
This is code of the element that is not working of index.php:
Link to abc
Which is the path that should work? I tried relative and absolut paths but I think I am writing it wrong.
try using html helpers for build the correct path
use yii\helpers\Html;
<?= Html::a('Link to abc', ['my-form/abc.pdf']) ?>
see here for more http://www.yiiframework.com/doc-2.0/guide-helper-html.html#hyperlinks
I resolve it doing the folowing.
I placed the abc.pdf file in the /backend/web folder.
Then I referenced it at index.php using:
<a href="abc.pdf">
if you just want to pass it in href attribute; use
Profile
I have some modules in modules folder that have css and js folder and I am thinking of the way how to approach the automatic load of all this css and js files to my header of the template.
I was thinking of creating 2 modules called cssloader and jsloader that will be included in the header section of the template.
They would contain some php script that will put the urls of css (and js) in an array and this array will be outputed in the template like e.g.:
<?php echo Modules::run( 'cssloader/cssloader/_css_include_for_frontend' ); ?>
The urls will be grabed by some script that will be searching modules folder of the CI application and looking for css folder within and a file load_css.php with some defined constants or variables like
$css_loader_frontend['slider'] = array('slider.css',
'slider_ie6.css'
);
$css_loader_backend['slider'] = array('slider_admin.css');
This file will contain files that will be loaded e.g. slider.css (within slider module css folder)
And the similar scenario for javascript stuff.
Is my approach right or not and you would do it somehow different?
What do you think about it?
What would you do different and more effective?
Thanks
I Think this template class can help you, though, I was wondering why are you accessing assets files inside modules, I'm not well versed but as far as I know you should access files such as img, js, css and so on just on the level of system and application folders in a folder that could be named "public" or "assets" to avoid "Directory access is forbidden."
I am brand new to PHP. I want to use it to include a universal header and footer in an html/jquery site. Currently I am using includes to do this:
<?php include('../includes/footer.php'); ?>
This works fine. Where I encounter a problem is with any images in the header or footer.
An explanation of my file structure:
Root folder: contains index.php and the folders "includes", "img", "php" etc.
php folder: contains gallery.php
includes folder: contains header.php, footer.php
When viewing the index.php all images in the header and footer show properly, but, because they are linked relatively (ex "img/facebook.png"), the do not show in gallery.php. To work they would need a ../ included. But then this would defeat the purpose of a universal header.
Thus I am trying to figure out how to link the images in the includes files in way that is doesn't matter where the php file is located. I have read this thread (which sounds like my problem) but I do not understand any of the answers. I have also read things that suggest $_SERVER['DOCUMENT_ROOT'] .'/folder/';, in conjunction with an echo to display the image. I tried this in my footer.php with this code:
<?php
$path = $_SERVER['DOCUMENT_ROOT'] . '/img/';
$image = ($path . "facebook.png");
echo "<img src=\"$image\" />"; ?>
When I view the page though, I end up with a little torn paper icon instead of my image. I assume this means that the path is incorrect, but I do not know why. facebook.png resides in the img folder. This problem occurs on both index.php and gallery.php.
After this rather long winded explanation (sorry), my mains questions are:
1) How do I get images to show up properly in my includes across multiple directories?
2) If I am going about this in the right way with the echo, what are the possible reasons why it is not working?
Once again, I know nothing about php, so if you could try to make your answers as basic as possible, it would be much appreciated.
Thank you!
Instead of img/facebook.png, add a / before the img/ like this: /img/facebook.png
This says "go to the root, and look for the img folder there. All your images should work fine then. The path of the images are absolute or relative based on the HTML page you're viewing, not which files you use to create it.
Though there's probably not much of reason for a "php" folder - just keep all your pages in the root directory.
i created a controller and actions in zend.
if i type
"http://localhost/cms/public/controller"
then the css file is loaded correctly
but if i type
"http://localhost/cms/public/controller/action"
then headlink appears like
href='http://localhost/cms/public/controller/css/style.css" and it does not work.
Please help me!!
this is the correct way to add css & javascript to ZF Application
<?php
$this->headLink()->appendStylesheet($this->baseUrl("css/reset.css"))
->appendStylesheet($this->baseUrl("css/text.css"))
->appendStylesheet($this->baseUrl("css/960.css"))
->appendStylesheet($this->baseUrl("css/demo.css"));
echo $this->headLink();
$this->headScript()->appendFile($this->baseUrl("js/jquery-1.4.2.min"))
->appendFile($this->baseUrl("js/jquery-ui-1.8.2.custom.min"));
echo $this->headScript();?>
You have your css path set to "css/style.css". Set the css path relative to the root path. If your css is in /html/style/css/style.css, the link would be "/style/css/style.css"
Always remember the leading slash and make the static paths relative to the root dir(of the website).