creating zf custom commands, like zf create form - php

When I use the zend CLI to create a form, like this, a form gets generated and gets added to the forms folder.
zf create form MyForm
I have a custom class that I'd like to create a custom command for it in the same way and would like to look at the zf create form command for guidance. I suspected it to be in Zend_Framework/bin where there's a shell, php, bat files, but I couldn't find any code there related to the form class creation, maybe i missed?
Anyway, is there a better to accomplish the same thing? like an Zend API that lets me create some of these commands myself? If not my only option would be to see how something like zf create form was created.

When you run zf, it invokes zf.php in the framework's bin folder. That in turn creates an instance of Zend_Tool_Framework_Client_Console, which jumps through some non-obvious hoops to load up all of the available actions and parse your command. Part of this process involves looking in the /Zend/Tool/Project/Provider/ directory, which houses the classes responsible for providing many of the project-oriented actions (like creating forms).
I haven't ever tried this myself, but there is (apparently somewhat outdated) documentation on creating your own providers, so hopefully following that will get you pointed in the right direction.

The ZendCast Integrating Zend_Tool Into Your Application is an excellent introduction to the whole business of creating Zend_Tool providers.

You need to create a provider. Look at this nice tutorial : http://weierophinney.net/matthew/archives/242-Creating-Zend_Tool-Providers.html

Related

Include User Custom Functions Best Practice in Symfony2

I am a newbie in Symfony2 and I can't understand where I should make includes with my custom cross-projects functions (e.g. array_merge_overwrite, array_last, etc.)? I use both types of apps: web (MVC) and console (extends ContainerAwareCommand).
Or there is another "right way" for this?
Create a service and put your common functionality in it. For example, you can name it ArrayService and register it in the container as array.service. You can then access this service from controllers via
$this->get('array.service');
and from commands via
$this->getContainer()->get('array.service');
So, your code will look something like this:
$element = $this->get('array.service')->last($array); // or ->arrayLast($array)
If you need the same functionality across several projects, make a bundle with that service and add it to the deps file of each project. Then it will be installed when you run the bin/vendors install script.
You can convert your functions to static methods of some class to make them autoloadable. Or... well... Place them where you want and require() from where you need them every time.

Symfony2 standalone form component - setting up a form

I'm trying to implement Symfony2 form builder component as a standalone. The documentation
doesn't really talk about this though, just in relation to using the whole framework.
The standalone is on Github but has no docs.
Ive searched around and seen a few people ask this question but none seems to have any answers.
All I need is a basic guide on how to setup a form , build it, then view it.
Anyone?
Edit: My first response below is now obsolete (and the link does not work anymore). Please refer to
https://github.com/webmozart/standalone-forms for a state-of-the-art solution.
Previous (now obsolete) answer:
I've tried hard and managed to display a form (using PHP engine, not Twig).
Indeed you need a few components: Form, but also ClassLoader, EventDispatcher, Templating (for rendering) and Translation (for rendering labels). You will also need some resources from the FrameworkBundle bundle (mainly templates).
More info on this:
http://forum.symfony-project.org/viewtopic.php?f=23&t=36412
And my mini-tutorial:
http://n.clavaud.free.fr/blog/index.php?article31/symfony2-standalone-form-component-tutorial
First, copy Form Component to your project to directory which contains third-party libraries (not only Symfony components, but also ORM or whatever), let's say lib/, so it's in <project_path>/lib/Symfony/Component/Forms.
Then you have to auoload it - either manually or using any PSR-0 compatible class loader i.e. SplClassLoader or Symfony's UniversalClassLoader (there is chapter in docs and in quick tour about this). Example:
$loader = new UniversalClassLoader();
$loader->registerNamespace('Symfony', __DIR__.'/lib');
$loader->register();
Using Form Component isn't in fact strongly documented, but in Symfony Book there are few examples how to use Form classes about this component, so I guess you'll have to dive into sources, beginning with Form class (maybe later you'll give some feedback about experiences somewhere in the Web?).
Since Symfony 2.1, the form component has been using composer.
You can locate the composer.json file inside the repository. It contains a dependency map that can be used to get the dependencies installed.
You can do so by simply running composer install from inside your console.
P.S I know this thread is old. The information I'm contributing apply to any new users that may need it.
First of all not with Symfony2. But creating form with Aura.Input and some view helpers of Aura.View makes it easy to bring Standalone Forms and Validation.
If you are interested you can read it over http://harikt.com/phpform/ , and source is in github.
/*
* This file is part of the Symfony package.....
what i understand from that line is that the file is a PART of the framework, can't be removed, can't be ripped, and it won't function if you rip it off the package because it requires other related files in the framework
however, there is an option, and it is to investigate the files and see what functions they call and what variables they use ,redefine them, and use it as standalone IF the license allows you to

Module-based projects: when to use them or not use them

I'm starting to familiarize myself with using the module-based architecture for zend framework projects. My real reason behind being interested in the module architecture is to be able to take a module from one project and just drop it into another project. Maybe I'm not getting it right..
But what I'm noticing right off the bat is that controllers within each module cannot have the same name as any other controller in the main application (or in any other module, though I haven't tested this). This leads me to think that modules are not really independent self-contained units, so I wonder how this affects their ease of distribution from one project to another.
The other issue is what if I were to take a module and drop it into another project. Do I have to update the .zfproject.xml manually? and wouldn't that be a bit too cumbersome to be done manually?
Maybe I'm not clear on how modules should be used in zend, so I'd like to know when you decide it's best to use them, and when do you decide not to use them, or do you use them all the time, or do you never use them?
I always used module based architecture so far in my projects, because I like to separate concepts. For example I have always an ADMIN module whose classes and controllers dont mix with the rest of the application. Using modules you can reuse modules for other applications, for example if you create a BLOG module.
The names of your controllers will be something like Admin_IndexController for the admin module even if the file is named IndexController.php.
Another concept that is nice and help you reuse resources is the plugins. Use them for authentication or to check validity of the requests.
You need to setup namespaces for your modules so that they are easily moved into a new project without renaming.
If you are using Zend Tool then you will have to edit the zfproject.xml. I haven't spent a lot of time using this so I'm not sure if there is another way without manually editing.

Command Line Tool To Supercharge Web Development?

Is there a way to create a command line tool which will help extensively in building an application.
For example, say I have a zend project and I want to add a whole new admin module based on some predefined patterns.
I run:
$ myzf create admin-module-framework
Which would then setup (as per a predefined template):
The module, models, views, controllers, actions, helpers, plugins, and even create a sql file to go with that.
Of course, I wouldn't be looking for something which simply copies certain files to certain directories (I can do that myself). I'd be looking for something which will actually modify the code to fit in with the app (based on some predefined variables).
Possible? Worth the effort?
Thanks!
See http://blog.stuartherbert.com/php/beyond-frameworks/ for a series of articles where Stuart creates such a system.

Is .zfproject.xml a must in a Zend Framework project?

Is .zfproject.xml a must in a Zend Framework project?
What does it do?
Is it's location absolute?
When using Zend_Tool to manage your Zend Framework project, .zfproject.xml will contain your application structure state. This is required by Zend_Tool (and only by it) to be able to work, e.g. add code to certain parts., generate things, etc.
Quoting ZF Manual on Zend_Tool_Project:
So, for example, if in one command you created a controller, and in the next command you wish to create an action within that controller, Zend_Tool_Project is gonna have to know about the controller file you created so that you can (in the next action), be able to append that action to it.
I am not sure if Zend_Tool can be configured to use a different path to .zfproject.xml. My suggestion would be to leave it untouched. It's a hidden file anyway.
Just to add, the zfproject.xml is not needed if you don't use Zend_Tool.
So it's not a must. Personally, I manage all my zf projects more or less without a command line and it works fine for me.
Basically if your going to use Zend_Tool, stick with it. Zend Tool doesn't like it when you create MVC manually. Its just another layer of abstraction that you can probably live without.
I am using zend framework 1.10. Whenever I create a action using zf tool it re-indents the code in the controller file and removes some function closing brackets. It is kind of buggy, so will not be using it from now on.

Categories