How should I set up my application when I can't change the document root? - zend-framework

I don't have permission to change the document root the /public/ directory so how should I set up my Zend Framework application to run from the current root directory? Using the Zend Framework 1.8 command line tool, I don't know if there is a way to tell it to create a directory structure this way.

If you can access only the upper level of web (i.e. - public), you should set index there and the whole application folder too. Create a .htaccess with
Deny from all
And put it into your /application.
Your configuration will be:
/application
/library
index.php

The simplest way without changing a lot of configuration, is to put everything in the public folder you mention into your public_html folder, then place all the other contents, like the application, and library folders into the directory up from public_html.
You can also throw everything into your public_html folder, although that is not recommended. Each class has options to provide a different path. For example on the Front_Controller, you can set the Controllers directory to wherever you want. There are options to specify different paths, but if you follow convention it is done for you.

Just use the quickstart guide and adjust according to it. Zend_Tool is still experimental anyway. Let me know if this helps.

So here's what I ended up doing:
Download the Quickstart sample code.
Move everything in public up to the main directory, along side application, library directories.
Alter include paths to library and application in index.php to point to the correct locations
I think that was all I had to do. ZF new how to the rest.
I don't think this is ideal however, as already mentioned, application directory becomes accessible from the web, but for now, it's getting the job done.

Related

Can we overlay the file to our custom path

Can we overlay the file to our custom path or we have to overlay the file to exact folder structure location as in libs?
For example, I want to overlay the constants.js (/libs/cq/ui/widgets/source/constants.js) file, in this adobe recommended Copy this file to /apps/cq/ui/widgets/source/constants.js for overlaying, but in my project that folder structure is not there, so I have copied to the custom path in apps folder and tested the changes and overlaying is working fine.
The file needs to have the same path as the one in libs except for replacing 'libs' with 'apps'. It does not work with custom paths*. If the project does not already have the structure, you can always create it. Don't forget to update the META-INF/Vault/filter.xml file to register the new path with projects package definition.
*Technically you can change the configs to add new searchpaths. But do remember that you might have to share the AEM instance with different tenants and sticking to the usual conventions goes a long way in having a predictable setup. I honestly don't see a reason to do this, it is already an acceptable practice to overlay under '/apps'. The filters on package provide enough flexibility to get along with other tenants while modifying similar areas.
I think you want to create the overlay in your custom project under /apps. If my assumption is correct, then you can certainly do it.
Taking your example in consideration, /libs/cq/ui/widgets/source/constants.js can be overlayed to /apps/<your-project>/cq/ui/widgets/source/constants.js by adding an entry in the Apache Sling Resource Resolver Factory configuration.
See this answer for the detailed steps. I hope this helps.

How to read a file in Play Framework 2.2.1?

I have a static file that I want to read in one of my Play Framework models. The file contains some simple text in it. I can't find any examples or API that shows where the appropriate location is to store such a resource and second, how to access that resource. For whatever it is worth I'm using Play for Scala, but I don't think that's relevant here.
There is no real designated location where data files should go. I usually set a path in my application.conf and then read it in the application via
Play.application().configuration.getString("my.data.path")
If you want to store it somewhere inside your Play application's directory, you can get its root path via
Play.application().path()
which returns a java.io.File.
For reading files, there is no Play-specific technique. This question has been asked and answered before. In short, to read a small text file, just do this:
val lines = scala.io.Source.fromFile("file.txt").mkString
You can place any resource file in the folder /conf and load it (Programatically) as explained here: Custom configuration files - Play! Framework 2.0
I have answered to a similar question at https://stackoverflow.com/a/37180103/5715934. I think the same answer will be applied for you too.
You can choose a location you prefer other than in dedicated folders for some specific tasks. For an example you can create /resources folder. Don't make any resource folder inside /app folder since it is only a location to store code. Same goes with other specific folders. Then you can use
import import play.Play;
Play.application().getFile("relative_path_from_<Project_Root>);
to access the file inside your code.
Only this will work perfectly on dev environment. But once you put this in production using the dist file it will not work since the entire resources folder you put will not be added to the dist. In order to do that, you have to explicitly ask play to add the /resources folder to your dist also. For that what you have to do is go to your /build.sbt and add these lines
import com.typesafe.sbt.packager.MappingsHelper._
mappings in Universal ++= directory(baseDirectory.value / "resources")
Now if you take and check your dist, you can see it has an additional folder 'resources' inside the dist. Then it will work for the production environment also.

Zend Framework Bootstrap with Layout?

So, I have a problem and I have been searching forever about how to do this.
I want to have several project directories on my shared host but I want to be able to hit the public directory when someone types in the root directory for that project. I can't edit the httpd.conf to set up virtual hosts so I have been looking for alternative solutions.
Account Structure
/public_html
.../Project1
....../application
....../public
I stumbled on http://www.mauriciocuenca.com/blog/2009/03/two-or-more-zend-framework-projects-on-a-shared-host/ and followed the steps (modifying some stuff since it is outdated)
And I can get a single view to show up. The problem is, if I create a layout I can't get anything but the normal view to display. I think I am just missing a simple hook up.
Is the above solution the best for my situation?
You problem is not 100% clear, I can't figure out that you want to serve one site per shared host directory or all site from the same directory.
Although you can't edit httpd.conf, you can use .htaccess file. While using Zend you already use .htaccess (located in public dir). So you can write rules to make url based redirections.

Fatal error: Class 'Zend_Form' not found

I've started using Zend framework, and Im following this simple Zend form tutorial. The form is located in application/forms directory I have included the Zend framework in the Path (by going to computer properties). However when i access form.php page, i get this error:
Fatal error: Class 'Zend_Form' not found
I have also tried by copying the Zend folder from the Zend framework in the library folder of the application, however error still remains same. Thanks.
It sounds like you are confusing two notions: the system path and the include path.
The system path is an operating system concept. When you ask the OS to execute a command, the system path is a list of places to look for the executable.
In contrast, the include path is a PHP concept that tells PHP a list of folders in which to look for files invoked by PHP include/require statements.
Any path that you find in "Computer > Properties" is almost certainly the OS-level system path. What you need to do is to make sure the Zend folder on the PHP include path, either by moving the Zend folder or by modifying PHP's include path to include a point to the Zend folder.
In a typical ZF app, the include folder is set in index.php (the front controller). So, the only explanation for not finding Zend_Form is that the autoloader is not being instantiated.
If you are using Zend_Application, this happens automatically. However, it seems like you are bypassing public/index.php and the whole Zend_Application instantiation by trying to directly "access" a file called form.php directly. If this file contains only the definition of your form (extending Zend_Form), then the absence of autoloading could easily explain the error message you are getting.
I'd try instantiating the form in a controller action, by which time in the request processing cycle, the autoloading is probably already in place.
[At that point, given the file locations you cite, we might run into a resource-loader issue, but that's a somewhat different issue that can be handled by instantiating a Zend_Application_Module_Autoloader in your Bootstrap.]
It looks like you do not use Zend_Loader. You should focus on it.
You can also manually in your custom form class include Zend_Form class.

Netbeans creating a dist jar with all images etc included

I am trying to distribute a netbeans project however the jar it creates and the contents of the dist folder are dependant on some image files which i included into the project - however these images are not in the dist folder and I cannot workout how to make things work so I can export the project in a distributable format including all the things it needs.
Can somebody please tell me how I can export a project which runs within Netbeans without using the project's /dist folder which includes everything it needs?
Cheers
Andy
One way to achieve this is to add a folder (f.i."resources") in your project's src dir. Then copy the images to that dir. Now the images should get included when you build the project (if I remember correctly). Accessing the files can be accomplished with "getResourceAsStream"...
If whatever resources you are interested in are in the classpath, packaged in the jar, war, or the distribution, you can retrieve them by getting resources.
The convention is indeed to have a directory named 'src/resources' that serves as the root for this. Depending on the amount and scope of the resources you are using you may also want to add a sub-directory hierarchy to keep the organization and state of the resources manageable.
Also, not that a resource can be any file, an image, sound, text, xml, binary, etc. no limitation.
Finally, the call will look like this if you are using an object method:
getClass().getResourceAsStream("resources/myResource") - or - getClass().getResource("resources/myResource")
depends on if you want a stream or just the URI at that point in the code. Typically one would use the URI for delegating the processing of the resource elsewhere and the stream form when you are processing it in-line.
For a class method, you will need to do something more like:
new Object().getClass()...
The think to keep in mind here, is eventually this is resolving to the class loader and it is from that class path that the resource will be fetched.
You can add images the same way:
final Image image0 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("images/1.png"));