how to get started with doctrine - php

where can i find help getting started with doctrine? forums etc?
I'm trying to follow this;
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/getting-started/pl
but it refers to a Doctrine.php file that's located in the lib folder. There is no lib folder in the doctrine download. There is a bin folder with a doctrine file in itIs that what they are refering to?
What should the folder structure look like for a doctrine project? Currently i have this;
application
library
|
|-----Doctrine
|
|------common
|------DBAL
|------ORM
Where should the Doctine.php file go?

Doctrine uses PEARlike naming conventions, so Doctrine.php goes into the root of your include_path, or to the root of your library, next to the Doctrine directory. However, newer versions of Doctrine1 only keep this file for backwards compatibility. You should rather use 'Doctrine_Core' it 's the same class, but with a new name (and location).

Related

Where do you place all your files for Zend Framework?

I completed the quickstart tutorial, but I feel really unclear on a few things. I started the guide initially expecting everything to be on my remote server, but it actually seems to be a guide for a local setup. I have everything on my server, and I have the hosts file on my local computer routing to the server, for ex. this is the entry in my hosts file server-ip quickstart.local.
1) Currently, I have everything beneath public_html. Where should I put all the Zend files (bin, demos, incubator, etc..)? www/public_html/[zend-files],www/public_html/quickstart/
2) Where do I put the quickstart (project) folder? Am I supposed to create an index.php that routes to the public folder in the project folder? At the moment, it is at public_html/quickstart/.
I feel silly and embarrassed for asking, because I feel like this is something really obvious.
Actually, you'll need only the Zend folder, which is the library itself.
On the public_html you need to put only the files located in the public folder of your project.
Folders like application and library should stay out of public_html.
For example
/home/my_project/public_html (public folder from zend)
/home/my_project/private (the other files, like application and library)
Instead of put the Zend library inside your project library folder, you can put it on the php include_path.
The second option, maybe the best, is to configure your virtual hosts and set the public folder (application public folder) as the root folder for your domain quickstart-local
So, you will end up with /home/my_project/public as your root folder and /home/my_project/application as your private folder.
You'll need to setup your index.php and application.ini with the appropriated paths.
As soon as you work with more than one framework version at a time, using symlinks becomes a good option. It is also much better for development than using the include path because you automatically have code assist for ZF code. We organize our projects as follows:
/application
/httpdocs
/library
/Project
/Zend (->symlink to the Zend folder of the needed version)
/ZendX (->dito)
/tests
And now, if you're about to say that 'symlinks' don't work on Windows, don't say it. It's utter rubish. It works perfectly well.

Modular Zend Framework app & Doctrine integration and usage

I need help, cause I am little stuck on this.
I have set up a modular Zend Framework app. Also using -- https://github.com/eddiejaoude/Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD- -- i integrated Doctrine 2.
My directory structure is like this:
-aplication/
--default/ --module1
---config
---controllers/
---forms/
---models/
---templates/
---test/
--maintenance --module2
---config
---controllers/
---forms/
---models/
---templates/
---test/
-config
--Bootstrap.php
--aplication.ini
-library/
--Zend/
--Doctrine/
--doctrine.php
--cli-config.php
-sites/
--site1/
---index.php
I have my databse created. I will use some tools to generate YAML files from database.
The next step I want is to generate model classes from these YAML files.
I spend days searching, but I just coudn't find solution to generate classes to models folder of each module. OK, so I would solve the problem by generating these classes in one directory and then move it to their 'original' destination (models folders).
I need help on how to generate these classes. I am developing in Windows, and that is where I want to generate this.
I suppose I have to open cms, point to location of doctrine.php (in library folder) and enter command php doctrine.php + some arguments. But when I do that i have:
[InvalidArgumentException]
There are no commands defined in the "" namespace.
What am I missing? What am I doing wrong?
I will also try to contact author of these files https://github.com/eddiejaoude/Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD- to ask for explanation.
Thanks in advance. I would really appreciate your help.
If you need I can write some of my code from Bootstrap and application.ini if you need.
Try to generate the class from YML file .It is possible to use MySQL workbench to sync the database tables and then use the MySQL workbench YML file generator plugin to generate the YML files . Hope it helps.

Autoloading classes when not in same directory as zend library

I've decided that rather than have a copy of the Zend Framework in each application's directory, I'd like to keep it on one location on the server, with the one copy used by all my websites. However, I'd like my app's custom classes to still be within the application folder. So a folder structure a bit like this:
webroot
|...library
| |......Zend
|
|...app1
| |.....Library
| |.......App1
|
|...app2
|.....Library
|.......App2
How can I get Zend Loader to automatically find the classes in App1 and App2? (preferably by just changing something in application.ini or bootstrap.php)
You can create a single library directory, with symlinks to the actual live shared code:
webroot/library/Zend -> /path/to/Zend/library/Zend
webroot/library/App1 -> /path/to/App1/library/App1
webroot/library/App2 -> /path/to/App2/library/App2
Then, you only need webroot/library in your path.
To handle version updates, you can simply change the symlink to point to a new install:
webroot/library/Zend -> /path/to/Zend-test/library/Zend
The Zend Loader will use your php include_path to find files to load.
Simply add webroot/library to your include_path (which you can either do in php.ini or in your bootstrap) and the autoloader should be able to find the framework.
If you are keen to have a shared version of Zend you may as well just use pear (http://pear.zfcampus.org/) to install it and then as long as you have your include_path set to look in your pear dir ( /usr/share/php on my machine ) then you are good to go.
I would advise only to do this for dev machines though, as others have said it's a good idea to be able to control the versions of zend for each app when in production.

What is the most scalable PHP-based directory structure for a large site?

I am creating a very large PHP MVC-based site that will have a large library of php classes, javascripts, and many css files (not to mention a large amount of files for the MVC).
For the first time ever, I am actually taking the time to plan out a clean and organized directory structure.
What directory structures do you typically use, and which will be easiest to manuever when there are thousands of files?
This is my setup. It's worked great for me for small - very large projects (including a social network).
These folders would all live within my main application folder:
config - contains custom PHP config files
css - contains the project's CSS files
helpers - contains 'helper' files (each file is a collection of functions)
images - contains the project's images
js - contains the project's Javascript files
lib - contains PHP classes specific to the project
modules - My MVC framework allows packaging site sections as modules
blog - An example module
controllers - contains the controllers for the module
models - contains the models for the module
views - contains the views for the module
views - contains views that should be globally accessible (page header, footer, etc)
All the directories could obviously contain sub-folders that would further organize your files. For example, the 'css' folder could have sub-folders named 'web' and 'mobile'. The 'images' folder could contain a 'user_uploaded' folder which could then contain`'profile'. And of course you can add folders as you see fit, in one project I have a folder called 'uploaders' which just contains stand-alone upload scripts.
I also use convenience methods which help construct the filenames of what I want to load. For example, my loadView() will look for the view file in the current module directory, or if you pass an optional $module argument, it will look specifically within that module's folder.
I hope this helps.
You should have one directory as web root, where only files you want exposed to the whole internet should reside.
project/
web/
index.php
css/
js/
images/
config/
lib/
web/ is the root shown to visitors
lib/ is here the library folder, and where autoload look for files.
You can add more subfolders to project/ like controller, modules, view, helper, etc. This depends on your framework.
EDIT:
If you use composer (which I recommend) and maybe npm with grunt and less your file structure would be the following:
project/
web/
js/
css/
images/
index.php
cli/
config/
config.php
node_modules/
src/
test/
vendor/
composer.json
composer.lock
packages.json
web/ has all your public files
cli/ scripts and programs to be run from command line NOT the web
config/ has all your config files (in git you ignore config.php and instead have config.dist.php without usernames, passwords, validation codes and table prefixes/suffixes and other "secrets")
node_modules/ has all your library files from npm (in git I suggest you put this in a submodule)
src has all your local PHP files in psr4 structure, set up to autoload in composer.json
test/ has all your unit tests for your src classes, set up in autload-dev in composer.json (remember to use composer install --no-dev on live, maybe add -o if you don't have too many classes)
vendor has all your library files from composer and the ONE AND ONLY autoload.php to be included in web/index.php and any cli scripts (in git I suggest you ignore this vendor folder)
Add other folders and files as required for your project.
For deployment use this structure:
/sites/project/ (project is your projectname)
current (alias to current release folder releases/v1.1.0)
previous (optional alias to previous release folder releases/v1.0.1)
releases/
v1.0.0/ (git checkout of tag v1.0.0)
v1.0.1/ (git checkout of tag v1.0.1)
v1.1.0/ (git checkout of tag v1.1.0)
shared/ (has all your shared files and folders to be aliased in all releases - maybe something like GlusterFS)
Make a deployment script. Something like this:
First take backup of db or to copy it to a new database, checkout git repo to new folder with release tag, get all git submodules, run composer install --no-dev, setup any aliases for shared folders and files like uploaded images and configuration files, generate js/css with grunt and less or equivalent, point current alias to the new folder with the tag, run update database script, restart nginx/apache/fpm-php services, run tests to check the website is up.
Have a script to go back to previous version (or a guide so you know what to do).
For core files which are included:
approot/inc/
For data access functions and classes are in:
approot/dao/
For javascripts:
approot/scripts/
For CSS:
approot/styles/
For images:
approot/img/
For static content (normally for user profile pictures or uploaded images):
approot/static/
For caches:
approot/caches/
For templates or View files:
approot/templates/
All pages file:
approot/
Structure from Samstyle PHP Framework
The answer I posted here was from 2009. Over the years more standards were published, including PSR-0 which covers the topic on folder structure. I also have a new (and I feel that it's better) folder structure with Packfire Framework.
In my experience, you can never plan for this. You can try to follow what frameworks do, but I find I never quite fit exactly into their mold.
I recommend to just keep a good rule of thumb for 20 files in a directory maximum. If you find you need more, just create a few sub directories and move common components in there.
This is mostly a matter of preference, a quick Google search would reveal many different project structures. But it would be really nice if there were an agreed upon standard. I think this initiative by the PHP Package Development Standards is a good candidate.
This is the directory structure they propose:
bin/: command-line executables
config/: configuration files
docs/: documentation files
public/: web server files
resources/: other resource files
src/: PHP source code
tests/: test code
EDIT:
This is also mentioned in the PHP The Right Way under the section Common Directory structure.
I use codeigniter for small and big projects.
It's MVC feature is moderately good.
codeIgniter\system\application\config : contain all kind of configuration files like DB,Payment gateway, ftp config, routes and ...
codeIgniter\system\application\models: contain all kinds of database classes, you should create sub folders according to your need, I used customers, mailData, paymentModel, report, web-service and ....
codeIgniter\system\application\views: contain all kinds of files that will work as output for clients, you should think of reuse these files if possible. Like the models you had to create sub folder like administration, reports, email, email_template .....
codeIgniter\system\application\controllers : this is the most important part. This will help to create SEO url, so you should be more careful about sub folders this time. You can create like administration, products, reports, orders..... and consider a good name for the functions of the controller class.
These were for the PHP/HTML file.
Now about the other files:
codeIgniter\images: for the images
codeIgniter\scripts: for the Java scripts and their framework
codeIgniter\styles: for the CSS
codeIgniter\uploads: for the uploaded files, if you don't want to put files in the DB
For the detail see codeIgniter framework in detail.
Here "codeIgniter\" is the approot
This is the structure i'm using currently,
public/
assets/ /* js, css, imgs, ... */
index.php
src/
config/ /* for config files */
helpers/ /* for functions */
libraries/ /* for free classes that are not MVC classes */
models/ /* for M in MVC */
views/ /* for V in MVC */
controllers/ /* for C in MVC */
vendor/ /* for vendors files */
uploads/ /* for uploaded images, docs, ... */
Have a look at symfony 1.4 or symfony 2 dir structure. Choose what's most intuitive to you.
I believe this depends on how large the project will become. This is what I used mostly:
project/
index.php
img/
css/
js/
views/
functions/
As long as all the project files are organised...
Even though the question is abit old, I still think it is wise to suggest the latest scaleable application structure which I have been working in my SOA based application and working absolutely fine.
myApplication/
app/
config/
+ this can include custom MVC structure
cli/
docker/
lib/ - most commonly reusable components
logs/
public/ - should contain all publicly exposable web contains
sql/ - db migration stuffs
tests/ - compulsory test
tools/ - application addon tools like any kinds of rulset etc
vendor/

PHP: Storing objects in a Symfony plug-in module's lib/ directory

I am building a Symfony project, and have created a new plug-in named sfUtilsPlugin. I currently have a directory structure that looks like this:
sfUtilsPlugin/
modules/
sfSearchLucene/
actions/
config/
lib/
templates/
Now, in the sfUtilsPlugin/modules/sfSearchLucene/lib directory, I have an object called sfLucene. The idea was that this object is accessible from the Symfony auto loading mechanism, so that it can be instantiated from anywhere within the application.
However, simply adding the sfLucene.class.php file to the sfUtilsPlugin/modules/sfSearchLucene/lib directory does not appear to add it to the autoloader.
Does anyone out there know why this might be happening? Perhaps it is just not possible to automatically use objects stored in this location inside Symfony.
Any advice is appreciated.
Because you are adding this class in lib subdirectory of module sfLucene, it will be autoloaded only if current module is sfLucene.
You have two options:
put this class somewhere into sfUtilsPlugin/lib directory;
require them every time you need it

Categories