Page 1 of 1

Zend Framework mhhhh....

Posted: Fri Jul 02, 2010 6:58 am
by ziuccio
Hello there,

I have another little prolblem executing my project structured on Zend Framework
I am new of php OO so I am studying all steps to build an application based on MVC pattern.

Under the folder c:\xampp\htdoc\ I have the folder tree of my project.
data
- logs
- tmp
- upload-files
htdocs
- .htaccess
- index.php
include
- Controllers
- - IndexController.php
- Zend
templates

in index.php I have written:

Code: Select all

<?php

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

$controller=Zend_Controller_Front::getInstance();
$controller->setControllerDirectory("../include/Controllers");
$controller->dispatch();
?> 
in IndexController.php

Code: Select all

<?php
class IndexController extends Zend_Controller_Action{
    public function indexAction(){
        echo "Web site home";
    }
}
?> 
In Zend foder I have copyed all the libraries of the framework v. 1.10.5
Now I have some doubts:
1) it seems that apache includes the internal libraries in C:\xampp\php\PEAR\Zend and not my libraries. Why?
2) when I run my application on the browser this error occours:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in C:\xampp\php\PEAR\Zend\Controller\Dispatcher\Standard.php:242 Stack trace: #0 C:\xampp\php\PEAR\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:\xampp\htdocs\zend\htdocs\index.php(8): Zend_Controller_Front->dispatch() #2 {main} thrown in C:\xampp\php\PEAR\Zend\Controller\Dispatcher\Standard.php on line 242
3) I use Eclipse IDE with some plugin for PHP. In the editor the row

Code: Select all

require_once 'Zend/Loader/Autoloader.php'; 
like every inlcude in the Zend files give me a warning for an incorrect path.
Include filename: 'Zend/Loader/Autoloader.php' doesn't exist in project: /zend

but There aren`t errors for classes and function not definied.
This is not a problem, just a curiosity... Why the call to Autoloader is working well if the path seems wrong?

I will be so pleased if you can help me

Thanks!

Re: Zend Framework mhhhh....

Posted: Fri Jul 02, 2010 8:15 am
by yochai20
You need to set the php include_path directive, if you have access to the php.ini, just edit it and search for "include_path", if you never edit this directive before you'll see something like "c:\php\includes"(for windows) if you use Unix Based OS, you need to write your path in unix style.

ohh i forget mention that the include path need to contain the Zend Library path.

Re: Zend Framework mhhhh....

Posted: Fri Jul 02, 2010 9:06 am
by ziuccio
If I include the path in php.ini adding
#include_path = ".;C:\xampp\php\PEAR"
include_path = ".;C:\xampp\htdocs\Zend\\include\"
I am going set this path for every project I have in htdocs.
But how can I set the path of a particular library for each project?
In Java I can set different Webapp libraries for every project deployed in Webapp folder under apache tomcat...

Re: Zend Framework mhhhh....

Posted: Fri Jul 02, 2010 11:00 am
by John Cartwright
set_include_path() + get_include_path()

Re: Zend Framework mhhhh....

Posted: Fri Jul 02, 2010 12:24 pm
by ziuccio
ok, and for trhe others problem?

Re: Zend Framework mhhhh....

Posted: Fri Jul 02, 2010 12:31 pm
by John Cartwright
1) I already told you

2) You need to create an default error controller.. perhaps something simple such as

Code: Select all

class ErrorController extends Zend_Controller_Action
{
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');

                $content =<<<EOH
<h1>Error!</h1>
<p>The page you requested was not found.</p>
EOH;
                break;
            default:
                // application error
                $content =<<<EOH
<h1>Error!</h1>
<p>An unexpected error occurred with your request. Please try again later.</p>
EOH;
                break;
        }

        // Clear previous content
        $this->getResponse()->clearBody();

        $this->view->content = $content;
    }
}
3. I don't know.. I do not use Eclipse.

Re: Zend Framework mhhhh....

Posted: Fri Jul 02, 2010 8:13 pm
by ziuccio
Thank you very much for your reply and sorry if I am asking very obvious things. I am new with Zend and PHP....