Setting up Smarty directories and paths - filesystems

Just a general question for those of you working with the Smarty templating engine.
How are you setting up your file structure? I'd like to follow an MVC format, but I'm not sure how to include all the CSS, Javascript, etc. with the Smarty controller and templates without including these ridiculous paths.
Has anyone worked with this? Anyone have any insight?
Thanks!
Matt

mmmmmm
I would recommend another structure.
suppouse this:
document root: my_app/public_html/
my_app/
- lib
- app
- public_html/
- css/
- js/
- images/
- cache/
- compiled_templates/
- templates/
- mails/
- html/
- text/
- frontend/
- backend/
- xml/
in this was your templates are outside the document root, so.. are protected. In the other way.. anyway can go to my/site/templates/somefile.tpl
your _public_html_ folder should contain all files that users can access.
the lib folder contains the all utility classes you may use: smarty, database, etc..
the app folder contains all the bussines files, etc..etc.
anyway I think the most important point is to have the frontend and the backend in different levels.
saludos

/
/includes/smarty
/includes/class.foobar.php
/includes/class.foobar2.php
/templates/myTemplate.tpl
/templates_c/
/js/
/js/jquery/jquery.js
/css/
/css/style.css
...
works nicely
including a file, which loads all stuff:
require_once 'includes/class.foobar.php';
require_once 'smarty/Smarty.class.php';

Related

CakePHP 2 path to webroot dir

How to create $this->Html->link(); to download file from Plugin webroot directory?
It's possible?
Why do you have to put the file in Plugin folder to be downloaded. This is not a good practice. Keep the file in webroot/file/name_of_folder
to get the path to webroot/ simply:
debug(WEBROOT);
Prefix with the plugin name
As mentioned in the docs, you can download plugin assets if the request url is prefixed with the plugin name (lower cased and underscored):
Simply prepend /plugin_name/ to the beginning of a request for an asset within that plugin, and it will work as if the asset were in your application’s webroot.
Note however that if the file is intended to be public it's a better idea for the asset to actually be in the webroot:
But keep in mind that handling static assets, such as images, Javascript and CSS files of plugins, through the Dispatcher is incredibly inefficient. It is strongly recommended to symlink them for production. For example like this:
ln -s app/Plugin/YourPlugin/webroot app/webroot/your_plugin
This would make it possible to access all files in a plugin's webroot directly without any rewrite or php logic being involved.

Grails 3.0 static html in run-app

similar questions have been asked before, regarding grails 2(.3, .4). I find it strange that i could not find a way to do this, as it seems a standard use-case to me.
I simply want to serve html-pages, including their linked .css and .js (angular and jquery content) when i run grails run-app.
I want to check if my http-calls are handeled correctly on both sides - without needing to deploy a .war and configuring a database.
afaik grails run-app simply starts a jetty/tomcat - both of which can obviously serve .html pages. What do i have to do to make the grails development-tooling deploy my files?
I need to make http-requests,
so using a different Server would violate JS-SOP,
while deploying the .war would greatly slow down the development process
I've so far only found clunky jsonp, proxy, .war deployment solutions, or solutions for grails 2.x
I tried placing the files literally everywhere in the projects' structure (/src/main, /src/main/resources, /src/main/public, the assets folder and its subfolders, created web-app directories in every subdirectory, the Init, domain, conf directories - you name it)
Add the index.html to src/main/resources/public
Then add this to UrlMappings.groovy:
"/"(redirect:"/index.html")
For grails >= 3.0.12
Location of static resources
In order to resolve an issue around how POST requests are treated for
REST applications on non-existent resources, static resources located
in src/main/resources/public are now resolved under the /static/** URI
by default, instead of the base URI /**. If you wish to restore the
previous behaviour add the following configuration:
grails.resources.pattern = '/**'
https://github.com/grails/grails-core/releases/tag/v3.0.12
Contrary to the accepted answer, you don't need a redirect. I have made able to make this work with the following config:
UrlMappings.groovy
"/"(uri: "/index.html")
application.yml
grails:
resources:
pattern: '/**'
Finally, you just need to have your index.html file located under src/main/webapp

How to set up a website's URL properly

I'm having trouble to decide how I should do to make my websites urls cleaner. The thing is, it's done with Angular AND Symfony2. Angular providing the front, and Symfony2 providing the api.
Here's my website's structure :
/api
/app => configurations go here
/bin => binaries
/src => your bundles/MVC code
/vendor => Symfony and 3rd party bundles
/web => this is where the web server document root should be pointed to
/front
/api -> Symlink to /api/web in the symfony part, working, but with app.php and app_dev.php
/css -> frontend CSS
/img -> frontend Images
/js -> frontend JS for AngularJS
/lib
/partials -> html templates used by AngularJS
index.html
Now the urls I get are www.project.dev/ which is home, rendered by AngularJS (/front), works perfectly, and www.project.dev/api/app(_dev).php/... rendered in Symfony2 but I want to remove the part :
app(_dev).php
I have two empty .htaccess, in / and in /api, do I need to use them ? Or do I have to use the Angular-route system ?
How am I suppose to do it ?
It's not clear how exactly you have your Symfony application setup, but I would recommend using the default Symfony directory structure, as it will simplify troubleshooting problems. The default directory structure is something like this:
/Symfony
/app => configurations go here
/bin => binaries
/src => your bundles/MVC code
/vendor => Symfony and 3rd party bundles
/web => this is where the web server document root should be pointed to
Since your document root is pointed to /web, you can have directories in there for your public assets, such as your /js, /img, and /css (Or you can look into Assetic, it allows lots of cool things like combining and compressing js or css.). The /web directory also has a .htaccess file included so that the app(_dev).php is removed from the URL.
Your /api can then be built using the standard Symfony routing, controllers, and views. You should read the Symfony routing documentation to get a grasp of how that works. A summary of how this works is:
create the route (ex. /api/users)
point the route to a Controller action (see the docs)
in the controller action, return the desired response
That's how I would recommend you structure your application. But if you would rather stick with the structure that you have, you will need to add a .htaccess file to the /api directory (which I assume points to the /web directory of the Symfony application), and take a look at this post for what the .htaccess file could contain.

Is there a simple way to share static website with complex directory structures on Google App Engine?

Im trying to get a static website structure to work on on google app engine. The site is fetched with -wget from a CMS that uses clean urls.
- www/
- index.html
- page-1/
- index.html
- subpage-1/
- index.html
- subsubpage-1
- index.html
- page-2/
- index.html
- somestaticstuff/-
- style.css
- image.jpg
- ...
The idea would be to get the following "clean url" structure to work properly.
myapp.domain.com/ -> www/index.html
myapp.domain.com/page-1/subpage-1/ -> www/page-1/subpage-1/index.html
Basicly route all trafic to public www/ folder.
If any folder has index.html show it.
Most common files shoud all be available from any directory path.
Been playing around with different yaml configurations from different tutorials but they only seem show how to do it on basic structures where you know how your site is structured.
Do i realy have to describe every single subfolder in the app.yaml one by one
as static_folder or is there a simpler way to describe this "reclusive" in the app.yaml.
I apologize if this question is noobish, im running out of time learning how this works and google doesn't seem to be my friend on this one.

Integrate Ext JS 4.1 MVC application in a rewriten URL (mod_rewrite) in development and production

Creating a new Ext JS 4.1.1 app based on the file structure section in Sencha's MVC Application Architecture guide I end up with this structure:
/wwwroot
/myapplication
/app
/controller
/view
app.js
/extjs-4.1.1
The app.js file contains:
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
appFolder: '/myapplication/app',
autoCreateViewport: true,
name: 'MyApplication',
controllers: [
...
]
});
All fine. I then include the app.js to be outputted in my server-side MVC application (not to be confused with the client-side Ext JS MVC structure). The language used and structure of the server-side application is of no importance to this question, but the result of the output is. In development, the URL of the application is:
http://servername/someidentifier1/someidentifier2
As in many applications, mod_rewrite is used to give meaning to the identifiers and map the URL to server-side code. These identifiers do not map to "physical" directories. The output of this URL is:
<!DOCTYPE html>
<html>
<head>
<title>MyApplication</title>
<link href="/extjs-4.1.1/resources/css/ext-all-debug.css" media="screen" rel="stylesheet" type="text/css" >
<script type="text/javascript" src="/extjs-4.1.1/ext-debug.js"></script>
<script type="text/javascript" src="/myapplication/app.js"></script>
</head>
<body>
</body>
</html>
Ext JS is not at the default recommended location, being /wwwroot/myapplication/extjs-4.1.1, but instead one level up since it is shared between multiple applications. If you look back at the app.js above, you also notice the appFolder setting which needs to be set in order for this to work with the "non existing" URL.
This all works fine in development, but the next step is to generate a "build" of the code with the Sencha SDK Tools (question is based on version 2.0.0 Beta 3 for Windows).
This is where it goes wrong. I take these steps:
Command line I go into the /wwwroot/myapplication directory.
I execute sencha create jsb -a http://servername/someidentifier1/someidentifier2 -p myapplication.jsb3 to generate a jsb3 file.
I execute sencha build -p myapplication.jsb3 -d .
The build fails. In this case because it tries to find the custom code for e.g. controllers in the path c:\...\myapplication\myapplication\app\controller: the current path + the appFolder setting. You would assume running it one level higher would be better, but then it cannot find the (shared) extjs-4.1.1 directory.
I would guess time will make the Ext JS MVC structure and SDK Tools more flexible and deviating slightly from the default structure is not recommended. All acceptable, but on the other hand: integrating Ext JS 4.x (Ext JS in an MVC way) with URL rewriting (mod_rewrite) must be a very common practice too?
Any suggested working set up/structure would be highly appreciated.
Goals should be:
No manual editing of the jsb3 file.
Keeping the extjs-4.1.1 directory at the top level to be shared among applications.
Having no app.html file since it is never used in server-side MVC applications and would otherwise require manual updates.
A nice extra would be to have the content of app.js inside the server-side generated HTML since it would then be able to receive dynamically generated parameters.
Couple things.
First - you don't need to specify absolute path for ExtJs library and for your app in the loader.
...
appFolder: 'app' // should be enough
...
Second - as for differences between build and production - I ended up having two .html files - index.html and index-dev.html. These files don't get changed (once you set them up) so it's not a problem to keep them in sync.
You use index-dev.html for your development needs, debug and also for build process. Basically this file is configured for your local development environment.
index.html just uses combined and minified version of your app.js and configured for production deployment.
Using mod rewrite you can use a slightly modified .htaccess file from Symfony
<IfModule mod_rewrite.c>
RewriteEngine On
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
This file let you
get resource from server if they are real files (css, js, images, etc.)
convert url parts to query parameters if there aren't matches on server filesystem.
This should work on your setup, just change the app.php line to your application entrypoint
for directory setup, yours is fine, just a couple of things:
your SDK tools are outdated, since you can download:
http://www.sencha.com/products/sencha-cmd/download/ (v3.0.0)
following docs at http://docs.sencha.com/ext-js/4-1/#!/guide/command you can get a "build" with the class you need, but in the end or you manually switch between development / production javascript file, or you switch using environments variables in your code.
Actually I think you could use a "fake" index.html in build directory to be modified by building tool then in production code you can mimic the code generated by sencha build.
Creating a index.html file to generate the project file will be a way to go. I also found that sencha architect is very rigid and hard to use. The most annoy thing is that I can't use the external editor to edit the generated code. Everything have to be done in the designer, which is fine if the designer can provide every functionality I need. But it can't.

Resources