-- WildFoxMedia <[EMAIL PROTECTED]> wrote
(on Wednesday, 05 November 2008, 02:48 PM -0800):
> Hey guys, im new to Zend, ive been a long time user of Cake, I have a few
> questions related to conventions, etc.
> 
> 1. Can someone possibly post a bootstrap/index file for a modular file
> convention where there are seperate controllers/views for public and admin
> modules that share models?

If you look at the QuickStart, you'll see the following directory
structure:

    application/
        controllers/
        forms/
        models/
        views/
            helpers/
            scripts/
    library/
    public/

Under the application/ directory, create a 'modules' directory, like
this:

    application/
        modules/
            admin/
                controllers/
                forms/
                models/
                views/
                    helpers/
                    scripts/

And in your bootstrap, simply add the following call after your
setControllerDirectory() call:

    $front->addModuleDirectory(APPLICATION_PATH . '/modules');

In terms of shared models, you have two options. First, you can simply
do require_once calls to the appropriate model in the appropriate
module. Second, you can put all shared code in your library/ directory
(I tend to lean in this direction for code shared between modules).

There is a proposal for a ResourceLoader action helper that would
simplify this, but it is not yet complete.

> 2. Is there a 'magic' save() method for saving to the database? I see
> currently there is Insert & Update, I dont mind using insert & update, was
> just curious.

There's not. I'm not entirely sure why Zend_Db_Table does not implement
this, though my understanding is that there are some sound architectural
reasons not to do so. I've often created such a method myself, though,

> 3. Is there any kind of table inflection when you insert or update? What I
> mean is if you have a table with 2 columns, id & name the array I try to
> insert has 3 array keys for id, name & created it throws an error - Cake
> does table inflection where it only attempts to save columns that exist in
> the table.

Again, there's not, and again, uncertain as to why. I've often
implemented such functionality for my own models, however.

> 4. Is there any decent way to autoload models instead of doing....
> $this->someModel = new someModel; in the init() of every controller?

No. If you're interested in doing something like this, however, you may
want to look at action helpers, and in particular how the ViewRenderer
action helper works (it does this sort of functionality for views).

> 5. Whats the correct method for gathering the filtered data from a
> controller, I saw in a tutorial where you basically check if the request is
> a post, then you assign the POST array to a variable, then you loop through
> each array key and do getValue() from the Form object...like this...
> 
> $formModel = new FormModel;
> 
> $dbRow = array();
> 
> foreach($postArray as $pKey => $pValue) {
> $dbRow[$pKey] = $formModel->getValue($pKey);
> }
> 
> Is that the best way?

No. Use Zend_Filter_Input or Zend_Form for this sort of thing. We do not
do automatic filtering at this time, but provide these tools so you can
explicitly define the validation and filtering rules you want to apply.

-- 
Matthew Weier O'Phinney
Software Architect       | [EMAIL PROTECTED]
Zend Framework           | http://framework.zend.com/

Reply via email to