Magento - where to add include files - magento

I need to include a php snippet to a few .phtml template files e.g. <?php include("foo.php") ?>:
Where is the common place to add foo.php? Can I just create a folder called "partials" in the root dir or is there already a special place for include files?

Related

xampp directly open my html file

I created folder called en407 and inside it i create a file called assigment that contain html , css and also php.
http://localhost/en407b/
When i click on the assginmnt file , i should let me choose what file to open
http://localhost/en407b/assignment
but the link directly go to my html file which is index.html and the link remains
http://localhost/en407b/assignment
in my assignment file , it contain index.html , index2.html and other....
how to fix it???
At first you can't run PHP in .html files because the server does not recognize it as valid till you tell it to do it. To do this create a .htaccess file in your root web directory and add this line inside it:
AddType application/x-httpd-php .htm .html
This will tell Apache to process files with a .htm or .html file extension as PHP files.

Blade templating

Is it possible to have the master.blade.php file outside of the template files.
Example below:
views/
master.blade.php
layout/
hello.blade.php
views/layout/hello.blade.php
#extends('layout.master)
I have tried the above but it cannot find the master.blade.php file. So is there a way to refer to a directory above the blade file.
it would be
#extends('master')
the "." in the view names indicate folders. so
#extends('my.long.path.to.template')
would be found in:
/views/my/long/path/to/template.blade.php
layouts don't have to be in a folder called layouts

PHPStorm: Syntax Highlighting for PHP code inside XML tags

Is there any way to make PHPStorm apply syntax highlighting to PHP code inside a tag in an XML file?
I'm working on an OpenCart project and I'm using Vqmod, which requires that I write PHP code in an XML file. For example:
<operation>
<search position="replace"><![CDATA[
<?php echo "123"; ?>
]]></search>
<add><![CDATA[
<?php echo "xyz"; ?>
]]></add>
</operation>
1) Settings | File Types -- assign *.xml (or whatever file name pattern you think is more appropriate) to PHP files entry (you may need to remove it from "XML files" first).
This will tell PhpStorm to treat such files as PHP (it's the only way to have PHP support).
The possible negative side -- it's an IDE-wide setting and will affect ALL such files in ALL projects. Therefore -- if you can name such files in some unique way (e.g. double extension: *.php.xml or *.xml.php; unique extension: *.pxml; unique file name ending: *layout.xml) then do it.
2) Settings | Template Data Languages -- find such files (or whole folder) and assign XML in 2nd column.
This will tell PhpStorm to treat such files as "PHP with XML" instead of default "PHP with HTML".
Official manual: http://confluence.jetbrains.com/display/PhpStorm/Syntax+highlighting+of+PHP+inside+JavaScript+%28and+other+languages%29

smarty relative links with in html templates?

how do we include style sheets from a template file in smarty?
ca we use a relative path or does it have to be n absolute path?
structure might look like
project
|-- library
|-- css
|-- style.css
|--template
|--index.tpl
|--template_c
in the index.tpl what would be the proper format to access style.css?
would it ../library/css/style.css? or
/project/library/css/style.css?
It depends on what you want to do.
If your goal is to have the browser access the css file, you need to specify the path relative to the document root. so, if your project lies within htdocs, it might be /project/library/css/style.css.
If your goal is to read the CSS within Smarty (say to inline it) you need to specify the absolute file path (e.g. /home/users/foo/project/library/css/style.css)
Accessing files relative to the current template file works with ./file and ../file - but only for {include} and {extends}. Everything else must either be absolute or relative to the CWD (current working directory) of the actually executed script.

codeigniter image path

I am a codeignite newbie and tried to add an image in my file under view folder.
I add <img src="../images/myImage.jpg"></img> to my service_view.php. All I can see is a broken link of a small icon.
however, if I change my path to
<img src="../../user_guide/images/myImage.jpg"></img>
I can see the image.
My file system is as follow:
application-
view ->folder (where service_view.php is located)
images -> folder (where myImage.jpg is located)
user_guide-
images ->folder ((where myImage.jpg is located))
Can anyone help me about this? Thanks a lot!
I would suggest storing images in an images folder at the same level as the application folder, instead of trying to mix both PHP code and resources underneath application. Then just link to it like you did to the user guide:
<img src="../../images/myImage.jpg" />
I know more than year has passed since the question was asked but for anyone who comes looking in future, Here is my solution....
I've tried this created a folder images at same level as that of application, in main index.php added a line before last require_once statement.
define('IMAGE_PATH', APPPATH.'../images/');
and used IMAGE_PATH anywhere I wanted to display images.
Hope this helps
I just have an image folder,
domain.com/images
then on the views i just use /images
<img src="<?php echo base_url(); ?>images/image.png" />
and put the images folder outside of the application folder in the same directory
Create an images folder at the same level of the applications folder.
With base_url() you can get the location of your site's base (cfr config).
This is useful because unlike site_url(), you can supply a string to a file, such as an image or stylesheet.
For example:
<img src="<?php echo base_url("/images/icons/stackOverflow.png"); ?>" alt="StackOverflow" title="StackOverflow is the best!" />
This would give you something like: ... src="http://example.com/images/icons/stackOverflow.png" ...
Source: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
it is better practice to upload the images in a folder that is present in the root or the site folder and use base href in the first line of head tag. then the whole page does not need and http path reference. just use the relative path. as codeigniter run using the index.php file in the root, we should use all the relative path w.r.t that index.php page
on local server try this
<img src="http://localhost/ci/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/>
on live use this
<img src="<?php echo base_url();?>/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/>
put a folder on your root directory such as "assets/images/" and the in your code just use it as
<img src="assets/images/imgname.jpg"></img>
Your file structure should be
-applications
-images
-assets
-Or any folder.
Keep the application folder, images folder, and assets folder inside the basic root folder.
Use when you want to include something from your root folder
FCPATH = C:\xampp\htdocs\your_root_folder\
<img src="<?php echo FCPATH; ?>/images/myImage.jpg" />
<img src="<?php echo base_url('/assests/images/image_name.jpg')?>" alt="">
This is the exact path for codeigniter, don't need write the "../../.." just write the path from assets (folder name)(sibling of application).
base_url gives the path of your project folder, not the path of the view folder inside application folder.

Resources