I got a simple question and can't find the answer to it on the web.
Im using the framework CakePHP.
My question is:
Is it possible to split my model, controller and view directories.
Like this;
Controller
CMS
[controller files of the cms]
Front-end
[controller files of the front-end]
Model
CMS
[model files of the cms]
Front-end
[model files of the front-end]
View
CMS
[view files of the cms]
Front-end
[view files of the front-end]
I really hope somebody can help me, because i have searched in the document 2.x Cakephp and search it all over the web and i cant find a solution for it.
Thank you very much
Not as such, but you can have two different app directories (because you are essentially creating two different applications).
CMS
Controller
Model
View
...
Frontend
Controller
Model
View
...
You can set up both apps to use the same webroot directory.
Besides creating multiple app-s in the cake installation, you should consider Plugins as well:
app/Controller/...
app/Model/...
app/View/...
app/Plugins/CMS/Controller/...
app/Plugins/CMS/Model/...
app/Plugins/CMS/View/...
app/Plugins/Admin/Controller/...
app/Plugins/Admin/Model/...
app/Plugins/Admin/View/...
(...)
See the docs: http://book.cakephp.org/2.0/en/plugins.html
You could define with App::build() the additional directories in your app/Config/bootstrap.php file.
Related
I started a project without using any framework.
My project structure was something like this:
A folder with classes to access my DB
A folder with classes for business logic
A folder with classes that can help me do other stuff
A folder with php pages that can be called inside pages(eg: navbar, footer, etc)
On root I had my php pages
So, calling all classes was preety easy. Now i am creating a new zf2 project and want to move all my work to this new project.I already setup the layouts and content of each page but i'm having some problems adding my custom classes. Should I use other kind of organization? Where can/should create my custom classes?
I also have some "php files" where I check some user info and depending on that, show him oriented advertisement. On my old project I was just calling it with "require"... can I do this on ZF2?/ is this the proper way to do it?**
Any help would be appreciated.
For anyone having the same question.
I created my custom library inside the vendor folder.
Here are some useful links:
http://code.tutsplus.com/tutorials/psr-duh--net-31061
http://ulaptech.blogspot.pt/2014/02/adding-3rd-party-libraries-to-zend.html
ZF2 follows the MVC (Model View Controller) design pattern.
So your directory structure looks like
module
Entity.php
EntityInterface.php
Table.php
TableInterface.php
TableFactory.php
The basic access methods are in Table.php
The mapping between columns and array is in Entity.php
If you would consult the tutorial Album application on the Zendframework website, you will see a working example.
How to organize controllers under /app/controllers in sub-
folders in CakePHP? I want to create a folder like admin inside the controllers folder and I want to create some controller related to admin. If it is possible, then how can i call a controller from a sub folder?
You can use App::build() to let CakePHP know for additional packages/configurations.
App::build(array(
'Controller' => array('/path/to/controllers', '/next/path/to/controllers')
));
You need to re-think your application structure. Cake has something built in called prefix routing that you should probably be using.
This is also available in 1.x
You can't alter the CakePHP file structure "just like that". It would require serious modification of the core to achieve this, but there is almost never a good reason to do so. If you properly follow the naming conventions, everything should be easy to locate.
What you could do (that is still following conventions and comes close to what you're looking for) is create a plugin for all your admin related tasks and then you can put all that logic under app/Plugin/plugin_name/Controller instead. That way it has it's own place, although you will need to load the plugin from you main application for this to work.
I can't find the documentation specifying how to set the public html directory. I am trying to keep all other files and folders in the site root. Since there is a frontend and backend public html folder, I don't see how this is possible.
My Site:
/site/perl/
/site/www/ <-How do you get just the 2 public folders here?
/site/.ssh
Yii Boilerplate:
runpostdeploy
yiic
/backend/
- /config
- /www/index.php
/frontend/
- /config
- /www/index.php
/common/
/console/
/tests/
Is the whole boilerplate project supposed to reside in the sites public html folder? I thought it was bad practice to do this.
*** U P D A T E ***
Spent most the day trying to figure out this problem. The closest thing I was able to find, was a comment on one of the Yii Framwork forum posts. For now, I'm running Boilerplate with subdomains like they recommend in this comment.
http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/#c9444
I'm not sure if this is the correct way. But it works.
You should set your site public director to frontend/www/. The idea behind Yii Boilerplate backend/www is to have separate domain for admin options (if needed), instead of having separate module. This way you'd be able to easily have separate CWebUser, Yii::app() etc. By the docs:
backend: the backend application which will be mainly used by site administrators to manage the whole system (avoiding admin modules at frontend application to avoid confusion)
I believe if you have two application, then you need two address.
You can do with sub-dir like this:
www.site-name.com -> ../frontend/www/index.php
www.site-name.com/admin -> ../backend/www/index.php
Or you can use subdomain like this:
www.site-name.com -> ../frontend/www/index.php
admin.site-name.com -> ../backend/www/index.php
It's like Wordpress, if you need enter admin page, you access through address www.site-name.com/wp-admin
But, be sure you don't use the 'admin' path in your frontend if you use this alias to backend.
Spent most the day trying to figure out this problem. The closest thing I was able to find, was a comment on one of the Yii Framwork forum posts. For now, I'm running Boilerplate with subdomains like they recommend in this comment.
http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/#c9444
I'm not sure if this is the correct way. But it works.
Alright, I know this is a bit localized, as I'm sure not many break out of traditional Zend Framework logic. But. This is a case where I have one main piece of software developed on ZF, and in it 3 different levels of platform.
So I have your stock folder structure of Zend Framework, then in it 2 additional sub folders that act as layers on top of the main structure. These sub folders have "layouts" "views" "controllers" and respectively "helpers" "scripts", etc.. so. With that due to how this was laid out I have run into a bit of a Jam, where I need to access a helper that is stored in one sub section from another sub section.
Normally you would access the helper like
$this->_helper->enrollHelper->isCreationDriven();
But, the controller I need to call this helper from is in another controller directory. Note I didn't build this app initially I am just helping enhance features and continue its growth. Anyway. The above line wont work for me in this case as the controller I want to call the helper from is outside of that directory in another like directory.
With that, My question is. Does anyone know a means I can call the helper in a similar fashion from this other directory? Or do I end up doing whats likely the obvious choice and just make a mirror copy of that helper in the other controllers directory where I want to call it from initially, my hope is there is a means as I want to avoid duplicate code.
During Bootstrap, you can register the second directory with the plugin broker using Zend_Controller_Action_HelperBroker::addPath($path, $prefix).
My site structure is currently like this:
/cms/
/data/ - caches etc
/modules/
/public/ - aliases from site public folders
/website1
/images
/layouts, views, scripts, css etc
(no index.php because of the alias)
This works fine, my system looks to the alias folder to run the app. However, I've now got to the point where I would like to extend one of the module controllers.
Ideally my structure would be:
/cms/
.. as above
/CLIENT_ID/
/modules
..extending/overriding scripts
However, this is the problem: the controller to be called must be called according to Zend's file name structure (Module_IndexController etc), so to extend the base classes would be:
Module_IndexController extends Module_IndexController
Which obviously wouldn't work nicely. My thought is that it should be:
CLIENTID_Module_IndexController extends Module_IndexController
But I'm stuck on ideas on how to implement this? I can add the controller directory using: addControllerDirectory on the front controller but I'm guessing I need to change the called class name somewhere?
I can then check if the folder is a directory and run the overriding class rather than the base one.
Any ideas? I'm open to restructuring the folders, but obviously need to keep media files in the public folder.
The problem is that you are not using the conventional directory structure that Zend_Dispatcher, Zend_Autoloader and Zend_Controller are programed to work with.
In my opinion you have two possible solutions:
customize Zend_Autoloader and Zend_Controller and Zend_Dispatcher. You can find possible customizations here, here and here.
modify the directory structure.
In this second case consider theese possible projectual choices:
create independent standalone zend framework projects for all the sites, and create in those the aliases of the CMS folders
like the previous but customizing the module locations with:
http://framework.zend.com/manual/en/zend.controller.modular.html#zend.controller.modular.directories
Use the CMS as a library: you put all the cms files in folder outside the /websiteN and then in websiteN's application.ini you set includePaths.library = /path/to/cms/folder". There are a lot of possible problems in this possibilty, that must be valuated knowing your project. In this way you can call models, extends websites's classes to extend cms's, but you cannot use your cms as the entry point and manager of the user interactions at variuos levels.
As you said, you can tell Zend the base controller directory for each module.
$controller = Zend_controller_Front::getInstance();
$controller->setControllerDirectory(
array("module_name" => "directory_path")
);
I would think Zend would want the naming convention to be ClientId_Module_Controller. But, if you really get stuck with the naming convention, and are using php 5.3 you could use namespaces.