Hi guys I am having a lot of trouble getting started with Zend Framework 1.12. Basically I've managed to get my project set up in Netbeans and I have it located on my localhost. When I go to this URL I get the default page:
http://localhost/zendtest2/application/views/scripts/index/index.phtml
But when I go to this page I get a list of my file tree in the localhost directory
http://localhost/zendtest2/
I guess what I am trying to understand is how to I get the http://localhost/zendtest2/ to point to the http://localhost/zendtest2/application/views/scripts/index/index.phtml or is that how I would even do it?
I know there is a public folder in my project with an index.php file. Is there some way that I should be reaching that page when the project initially starts?
To me this sounds more like an environment issue rather than a zend framework issue. I am not entirely sure what your dev environment is, but I am going to assume you're using apache as your HTTP server:
https://wiki.apache.org/httpd/DirectoryListings
Again, I am not entirely sure what OS you're using so you'll need to find your httpd.conf file yourself.
You then have two options, adding the redirect/route there (that may be wrong) or (more recommended) uncommenting the httpd-vhosts.conf link:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
Then including the new route in there. Heres a basic example (again you'll need to add what you need):
<VirtualHost *:8888>
ServerName zf2-tutorial.localhost
DocumentRoot "/Users/stevenc/****DIR_STUFF****/skeleton-application/public"
</VirtualHost>
Anything beyond that can be set as your home route in the module.config.php of the Application module within your zend project:
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'BookList\Controller\Book',
'action' => 'index',
),
),
),
Also, if you're not using ZF 1.12 for any particular reason, ZF2.3* is the latest.
Related
I am setting a demo Zend project on a windows server.
That is having base url like http://example.com/JPZend/public/
But on some url like http://example.com/JPZend/public/user/index?page=2
it gives the following page not found error where http://example.com/JPZend/public/user runs perfectly.
Page not found
Exception information:
Message: Invalid controller specified (JPZend)
Request Parameters:
array (
'controller' => 'JPZend',
'action' => 'public',
'user' => 'index',
'module' => 'default',
'page' => '2',
)
What am I missing? Seems like some virtual hosting issue?
Normally, you use the public folder as your webroot.
So your URL would look like this: http://example.com/JPZend
The default route in ZF is:
:controller/:action
Or with Modules enabled:
:module/:controller/:action
To tell ZF that you have another Base URL, you need to add a line to you application.ini:
resources.frontController.baseUrl = /JPZend/public
And to your .htaccess or similar under windows:
RewriteEngine on
RewriteBase /JPZend/public
Have fun!
I have a few modules and the Zend Framework library in "C:\Public\vendor" folder. The directory looks like this:
vendor
--> Module1
--> Module2
--> ZF2
----->library
------->Zend
In my PHP application, which is actually located in "C:\Public\apps\myApplication", I am able to get the Zend Framework path, by setting a ZF2_PATH environment variable in my apache's httpd-vhosts.conf file.
However, to get the Modules to load, in application.config.php, I am having to mention the physical path of the module location (which might change in a production environment), ex:
'module_paths' => array(
'./module',
'./vendor',
'C:\\Public\\vendor',
),
Is there a way to set and retrieve, module_paths using an environment variable in apache?
Why forget about normal PHP just when working with a Framework?
$modulePaths = array();
switch ($env) {
case 'local' : $modulePaths[] = ....;
// other cases ....
}
'module_paths' => $modulePaths,
I modified my code like this to read the environment variable, set in apache and it worked..
'module_paths' => array(
'./module',
'./vendor',
getenv('CUSTOM_MODULES_PATH'),
),
Thanks for your input Sam..
Is it possible to put and run modules in yiiboilerplate common section?
If it could, how it configured?
Thanks,
Just configure the module with a path alias, as far as I can tell there is an alias root which points to the project root.
'foo' => array(
'class' => 'root.common.modules.foo.FooModule',
),
You may also have a look at this config file from my boilerplate, which does the same.
I'm creating a small FuelPHP application that contains a blog module. In this module the posts controller just assigns a simple view to the template for the posts index.
I have read through the FuelPHP docs and have the following settings in the app config for the modules:
'module_paths' => array(
APPPATH.'modules'.DS,
APPPATH.'..'.DS.'globalmods'.DS
),
'always_load' => array(
'packages' => array(
'auth',
'orm',
),
'modules' => array(
'admin',
'blog',
),
),
The application itself is outside my WAMP www docroot but the assets, htaccess and index.php are inside.
I have no idea why the server cannot find the localhost/blog/posts/index URL as I have followed everything advised on the docs and the homepage (root route) seems to display fine. It is only when I click the blog link (blog/posts/index) that it states
"Not Found
The requested URL /blog/posts/index was not found on this server."
Any help would be much appreciated!
I had the same problem myself. Two key things I did were:
1) Start with a fresh copy of Fuel. I was missing some sort of configuration file, so I create a brand new Fuel framework, and then added all the app files back in
2) Enabling the 'rewrite_module' in the Apache Modules (in the Wampserver config)
Try these two things and see what you get.
In the sceleton application that I've downloaded from github there is a file
module/Application/config/module.config.php
return array(
'layout' => 'layout/layout.phtml',
'display_exceptions' => true,
'di' => array(
'instance' => array(
'alias' => array(....
this file is used in module/Application/module.php:
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
How to create 3 different configs depending on domain (production, staging, development)? It seems in ZF1 env vars has been used, but I don't know how to do that in zf2 module.
Thank you!
Create a file called development.config.php in application/config/autoload and this will be loaded after all the modules' config files have been loaded. As a result, you can override anything the merged configuration by adding the relevant keys to this file.
The name of the file loaded is {APPLICATION_ENV}.config.php, so you can create production.config.php, etc.
Note that you may have to change the glob in index.php as it's unclear if the Skeleton application will work out of the box with APPLICATION_ENV or not at this stage of the development of ZF2 (early April 2012).
it seems to work with a simple .htaccess change. :
SetEnv APPLICATION_ENV development
I don't know if staging will work, but production and development work out of the box.
I think it works through the event listener, but don't ask me how, I haven't gotten that far yet.