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.
Related
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.
I have a controller named CategoryAdminController.php which can be accessed by {siteurl}/categoryadmin/index in my localhost which is on a Windows machine. But when I try to launch it in my remote server which is on a Linux platform, it is unable to load the page. But when I rename my controller as CategoryadminController.php (and the class name accordingly), it is working fine.
Is there any way to load the page while keeping the original name in the controller (ie: CategoryAdminController.php)
According to Yii guide, seems it is not possible.
http://www.yiiframework.com/doc/guide/1.1/en/basics.convention
Any ideas?
Thank you
To keep Controller names and Action names CamelCased and working on Linux, you need to add dash between each word in the URL:
"{siteurl}/category-admin/index" -> CategoryAdminController->indexAction()
"{siteurl}/category-admin/my-way" -> CategoryAdminControllern->myWayAction()
This will work both on Linux and Windows.
Windows reads files and folders case-insensitive. And often hides some of the mistakes.
The common issue comes when you develop on Windows ... and create a link categoryadmin the OS will find be happy to give you a file like
CaTegoRYadmiNcontroller.php ignoring the capitalization.
But when you deploy the same code and files on Linux you will get File Not Found exceptions.
So, better stick to the convention.
It is case-sensitive for a file's name when on a Linux OS, but not on Windows. Did you try to access it: {siteurl}/categoryAdmin/index ?
You can rewrite the URLs by using the urlManager. In your case you can use the following code:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => FALSE,
'rules' => array(
'categoryadmin/<action:\w+>' => 'categoryAdmin/<action>'
),
),
This is because I want to develop a web platform with more than one application in the same project.
In any MVC web application we should have this default URL schema:
domain/controller/action/parameters
1: In Zend, what can I do (in which files) to change this schema to add the application name before the controller name?
Expected Result: domain/application/controller/action/parameters
2: How can I implement the consequences of this new URL block in terms that I will separate the MVC for each application, maintaining the shared resources in a separate directory? What changes may I do in Zend autoloader
Expected Result:
/public_html/
/public_html/platform
/public_html/platform/apps
/public_html/platform/apps/base (user interface container)
/public_html/platform/apps/crm
/public_html/platform/apps/crm/model
/public_html/platform/apps/crm/view
/public_html/platform/apps/crm/control
/public_html/platform/apps/crm/public
/public_html/platform/apps/crm/public/css (and etc.)
/public_html/platform/apps/erp
/public_html/platform/apps/erp/model
/public_html/platform/apps/erp/view
/public_html/platform/apps/erp/control
/public_html/platform/apps/erp/public
/public_html/platform/apps/erp/public/js (and etc.)
/public_html/platform/sys
/public_html/platform/sys/core
/public_html/platform/sys/cfg
/public_html/platform/libs/
/public_html/platform/libs/zend
/public_html/platform/libs/template_it
/public_html/platform/libs/custom
i think it is as easy as having actual different ZF2 application, every one in its own folder, and in the same level, a "vendor" folder where you put all the shared structure (coming from zend, third party libraries, etc).
Then inside the vendor folder, i would create another folder for your own shared code, including all your modules that has to be used by more than one of the applications, so your code is a library for yourself.
Since your app is actually in domain/application, and everyone has it own config, it is very straightforward to have domain/application/controller/action/parameters routes: you just create your normal controller/action/parameters routes, since the app actually resides in domain/application/ and the router doesnt have to care about it.
As you noticed, another problem is the autoloader. YOu just need to update the references to the shared modules inside your application.config.php for everyone of your apps
return array(
'modules' => array( //....
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php'
),
'config_cache_enabled' => false,
'cache_dir' => 'data/cache',
'module_paths' => array(
'./module',
'../vendor',//reference to your library modules
),
),
//...
);
of course, if the modules doesnt reside directly inside vendor/module but something like vendor/libraryname/module, you have to take a look at your autoload system (Composer autoloading or whatever) and add the classes or namespaces to the corresponding maps.
I just created a module with a submodule like Backend\Entity1. I checked every path and namespace, they all seem to be ok.
I took out codeblocks one by one but stil I just get via Firebug a
"NetworkError: 500 Internal Server Error"
Any ideas what I can do to find the error?
I just don't know what might be wrong. Honestly, why does the framework explain itself what is happening? Its just fishing in the dark now...
BTW: The error.log doesn't show something either...
Edit:
I'm guessing that this error is raised because my app can't find the phtml files. Maybe I'm wrong but usually when I get this kind of silly error it has something to do with missing files...
My config code looks like this:
'view_manager' => array(
'template_path_stack' => array(
'entity' => __DIR__ . '/../view',
),
),
My namespace is MasterData\Entity and my add/edit/delete/index.phtml lie under view\masterdata\entity.
Any ideas how I can tell the TemplatePathStack how to look in this dir for my files?
If your want your sub module to be accessed create proper route in the parent module to make a way to access your sub module.
I IMHO if you need to create sub modules, create as module and place the modules under modules folder of your application, if you have components or third party modules place it under vendor folder.
This would be easier to manage at later stages an your url will also be much simpler
In my case, I created the new model in another way but I had the same error when I tried to see the result in the explorer. The problem (in my situation) was the access to files from the explorer, It resolves by changing files's permissions in linux's terminal.
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.