Passionate Engineer
Passionate Engineer

Reputation: 10422

Zend framework form helper

I'm trying to work out how below works...

Where does Jobs_Form_Report_Productivity() come from?

public function productivityAction(){
        $this->view->headTitle('Number of Unique Jobs by Portfolio');
        $this->view->form = new Jobs_Form_Report_Productivity();

        if($this->view->form->isValid($_POST))
        {
            $report = new Model_Users();

            $this->view->results = $report->reportProductivity(
                $this->view->form->getStartDate('yyy-MM-dd'), 
                $this->view->form->getEndDate('yyy-MM-dd')
            );
        }

    }

Is this some form of Model class?

Upvotes: 0

Views: 178

Answers (2)

Stoyan Dimov
Stoyan Dimov

Reputation: 5549

Zend Framework use Zend_Loader_Autoloader to load classes that are called but not found in the script scoope. When a class that isn't found is called the autoloader kicks in and find and include the class file in few simple steps.

1) Converts all the _ (underscore sign) into / (slash) in the class name. Example: Zend_Loader_Autoloade becomes Zend/Loader/Autoloader

2) The suffix .php is appended to the end of the converted string and it becomes: Zend/Loader/Autoloader.php

3) Checks if the "Zend_" name space (name space as class prefix and not PHP5.3 namespace) is registered with the autoloader. If the name space is registered then the autoloader will issue: include Zend/Loader/Autoloader.php.

4) If the class is found it returns it and the script continues. If class not found based on the configuration throws and exception or error.

PRE-CONDITION: The file Zend/Loader/Autoloader.php should be in the PHP include path for the current script.

Therefore, Jobs_Form_Report_Productivity will correspond to Jobs/Form/Report/Productivity.php and it will be found in one (or more) of the include paths. Find the include paths with PHP's: get_include_path(). Most of the times (in ZF1) the include path(s) is/are set in the index.php file in the public directory of the Zend Framework application.

See: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md as the guys from PHP-FIG made this autoloading approach a standard "PSR-O"

Hope this helps :)

Upvotes: 0

MonkeyPHP
MonkeyPHP

Reputation: 36

ZF1 uses PEAR namespacing (note the underscores), each underscore becomes a directory separator and the last part of the classname is usually the name of the file typically something like 'Productivity.php', so Jobs_From_Report_Productivity should be located in Jobs/Form/Report in a file called 'Productivity.php'. Since the classname you are looking for does not start with 'Application_', my suggestion is that it is a module namespace called 'jobs', so you are probably looking for 'application/modules/jobs/forms/report/Productivity.php, otherwise it could be in the library directory as library/jobs/forms/report/Productivity.php. Of course, its completey possible to do some weird and wonderful things with the locations that ZF1 uses to locate classes.

Upvotes: 2

Related Questions