Where should additional files be put when writing my own magento extension? - structure

I'm writing my magento extension and came up with a question. The main extension files/directory structure is quite clear. We have dirs for extension configuration files, models, helpers, database resources, frontend and backend scripts and stylesheets etc.
But what if my extension uses some files that aren't classes or resources to be included to frontend or backend?
For instance: image files that will only be attached to emails and will never be retrieved by a browser directly.
Should/could I just create a directory /app/code/community/MyNamespace/MyExtensionName/images?
The same dir tree for better readability:
app
code
community
MyNamespace
MyExtensionName
images
Or is there any other correct/recommended way to achieve that?

There's never been clear guidance on how to do this from Magento Inc. itself, and Magento's module structure doesn't offer clear guidance. The approach I've always taken is
Pretend I'm on the Magento core team
Pretend my fellow team members are sociopaths who don't care if anything I've done breaks
If you're adding frontend files for public consumption (to js, skin, etc), I always create a folder that's a lowercase version of my full module name, and drop all files in there
/js/namespace_modulename/file.js
In the case of files that aren't going to be served publicly (i.e. you only need access to them via PHP), creating a folder in the root of your module (as you've done above) is appropriate. I'd suggest something like
app
code
community
MyNamespace
MyExtensionName
assets
images
You never know when there'll be something else you want to add, and having everything under one folder will help keep the module structure clean.
There's even sort of a precedent for this in Magento's core code. Take a look at the
app/code/core/Mage/Sales/doc
folder.

Create a folder into media directory and place your files/images into that folder
media
MyExtensionName
images
And access them like
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'/MyExtensionName/images/pic.jpg';

Related

Can I change where root requests resolve to in an express app?

I've created a small Express app that essentially serves as a file browser for our department's work. Users can drag their files and folders onto a network drive, and the app presents this folder structure as a browsable web directory for my colleagues to view various simple static files such as html files, images, css and javascript.
This is extremely business critical, and has worked flawlessly for over a year now, but there is one feature that I'd like to add. Occasionally the work contained in a subdirectory is a slightly more complex project, and there would be a huge architecture/complexity benefit from it being able to reference files from its own root path. I'll try and explain with a small example:
/app
/projects
/project1
/project2
/index.html
/styles.css
/finished
/project3
It would be great if there was a simple way I could declare the base url of project 2 to be /app/projects/project2 so that I could reference the css file from the html with href="/styles.css".
I've read that I could do this by creating a second express app for project2, and then route requests to /app/projects/project2 to that app, but this requirement crops up quite regularly and the thought of configuring/managing a multitude of sub apps without breaking the main viewer doesn't seem like fun!
Is there a simpler way? I'm thinking of a special designation in the subdirectory name e.g. "wwwproject2" that could get the app to adjust where it maps root requests to.
I'm sorry if this all sounds insane to those with more knowledge than me!
I don't think there is a way to do that.
But you could simply reference it by using the relative path to it -> href="./styles.css"

how to upload site to the server

I have a question....I'm using FileZilla to upload my eclipse project to the server. Now, it's the first time I do that and I don't know where to start. (I really don't want to do disasters)
in this image there is the composition of folders: on the left there is my project and on the right there is the server's folders.
http://img22.imageshack.us/img22/2519/jbecagca.png
In the folder WebContent I have also my 4 html files and one of these is index.html that is the page that has to be shown when I write the url of the site.
Now the question is... Where do I have to put my servlets? where my classes? where my sql dump of my database? where my html pages? where my js files?
I really have no idea.
thanks for any help!!
Go to your web host ask address for sql database you need to make a database on any of their server then it can be used you cant just use by uploading .
js files and classes will be used same hierarchy you used time of development.
If you're uploading a project, you should probably keep the project's folder structure. You should upload the whole project folder as is to the webroot, so you can access it from your browser

JBoss 7 - using *.properties files from filesystem

I have a webapplication (maven,spring,,hibernate) which contains different *.properties files which can be found within src/main/resource. Now my customer want to edit this files (e.g. change email address..) --> whats the best solution/ best practise? exclude *.properties from .war file and put it into filesystem? Jboss modules?
Can someone give me a hint?
If I were you I'd move these properties from static files to a persistent storage (i.e. DB) and then provide a UI to end user to modify their values.
Writing a custom module might work. This isn't as bad as it sounds, check out HowToPutAnExternalFileInTheClasspath.
See also migration-issues-to-jboss-7-1 and Where to put property file in JBOSS 7 or Glassflish? (Best practice)

Display list files and folder using Mediafire API

I tryed to use Mediafire API, but when I use Folder, get_info, it doesn't return file & folder array like the example.
Full url I used: http://www.mediafire.com/api/folder/get_info.php?folder_key=l461cm2d8hfxd
What's wrong with my attempt? Thank you.
You can try the MediaFire API PHP Library. This class currently implements all the functions in the Mediafire API.
Ok I just took a look at their API documentation. They've updated the get_info function for the folders. They've taken out the file tree....
So if you are uploading via the dropbox (which doesn't return the quickkey associated with the file), you CAN NEVER dropbox upload and then use the api to find the file and download it. This renders their API as useless as tits on a boar hog.
The point of a dropbox is to allow remote uploads to a folder, you then know the folder key so you can query the API and return the document quickkeys that are in the folder which then allows you to manage those files remotely, move, delete, download etc. Now you cannot do this FAIL FAIL FAIL.
Despite the Functionality of get_info not working, folder search can resolve at least some issues with retrieving quick keys. In my case i searched for ".mp3" and was handed all the mp3s in my folder

How to use relative URL's in website with two base URL's

I have our basic corporate static html website installed in our web root directory and our billing software installed in /portal. I have integrated the websites to look like a single site by including the /menu.tpl smarty template file in the /portal/header.tpl file. However, if I use relative URL's, the menu sysem doesnt work as the base url for the billing script is /portal. i.e. if I create a link to faq.php in the menu.tpl and I load a page on the portal site, the link in the menu back to the faq page is now /portal/faq.php whereby if I load a page off the root site the link is just /faq.php as it should be.
The obvious answer is to just use absolute URL's, but I need the site to be portable as I have many developers who need to install and test it.
I cant find anyway to resolve this. Any ideas?
I ran into the same problem as you a while ago, and after trying a lot of dead ends, I finally ended up with the following solution:
For any URL you need to be a chamelion, i.e. change its path depending on the environment, insert a PHP function that writes out the correct URL.
If you include the PHP function from a single central file, then you can change all of the URL's in the entire site automatically, based on a setting, or some pre-detected switch such as the current domain name, etc.
Example:
<?php print_base_url_plus("/menu.php"); ?>
... where print_base_url_plus() is a function which appends the base URL onto the output.
You may find that you have to change some of the URL's to be php, so they are preprocessed by the PHP engine, or, you can alter the web settings so that standard .htm files are piped through the PHP engine, just like .php files.