Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8318529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:00:27+00:00 2026-06-08T22:00:27+00:00

I have a class which is in a subdirectory of my library-folder in a

  • 0

I have a class which is in a subdirectory of my library-folder in a zend-project. So lets say my app is in /Library/WebServer/Foo/, then php’s include path is:

<?php echo get_include_path(); ?>

/Library/WebServer/Foo/application/../library:/Library/WebServer/Foo/library:/usr/share/zend-framework/library/

So now I want to create this class, ignore the random logic, and I should be able to reach it by just saying “new MyValidator_Usernameunique()” or something like that:

/Library/WebServer/Foo/library/MyValidator/Usernameunique.php

class MyValidator_Usernameunique extends Zend_Validate_Abstract
{
     const USERNAME_ALREADY_EXISTS = 'usernameAlreadyUsed';
     const DATABASE_FAILED = 'userDatabaseFailure';

     protected $_messageTemplates = array(
         self::USERNAME_ALREADY_EXISTS => "De gebruikersnaam '%value%' is al in gebruik, gebruik een andere."
         self::DATABASE_FAILED => "Er ging iets mis bij het verbinden met de database."
     );

    public function isValid($value)
    {
        $magic = rand(0,3)
        if($magic==0) {
            $this->_error(self::USERNAME_ALREADY_EXISTS);
            return false;
        }
        if($magic==1) {
            $this->_error(self::DATABASE_FAILED);
            return false;
        }
        return true;
    }
}

So I did exactly that:

/Library/WebServer/Foo/library/Form/Register.php

class Form_Register extends Form_FooForm 
{
    public function __construct() 
    {
        parent::__construct();
        $username = $this->createText('username', 'Gebruikersnaam')->setRequired(true);
        $username->addValidator(new MyValidator_Usernameunique());
    }
}

Which gives:-

[Wed Jul 11 14:07:41 2012] [error] [client 127.0.0.1] PHP Fatal error: Class ‘MyValidator_Usernameunique’ not found in /Library/WebServer/Foo/library/Form/Register.php on line 14, referer: http://foo/

ignore the line number as I simplified the code a bit.

Of course, this comes natural as /Library/WebServer/Foo/library/MyValidator/ is not in my php include_path and I did not ‘require’ or ‘include’ or ‘require_once’ the file. Yet, as I understand, zend framework is supposed to autoload the file by replacing the _ with / and searching the include_path. And this seems to work fine for the register-form, but fails for the validator. Now, why is this? It is almost the same scenario. Moreover, it also fails when I try to create a MyValidator_Usernameunique directly in a controller-class with the same error-message.

Any thought or indication on why this happens is well appreciated. Moreover, please note, I I am not trying to fix this error, I am trying to better understand autoloading in zend. So please do not propose solutions which make the use of my validator redundant.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:00:30+00:00Added an answer on June 8, 2026 at 10:00 pm

    Looking at your code, and i might missed it, but it’s not really the “standard” zend layout

    i kind of expect to following
    in the path of your webapp (/Library/WebServer/Foo/)

    • application
      • configs
      • controllers
      • etc
    • library
    • public

    Now you want to add the validator to your library i would do it like

    library

    • MyApp
      • Validate
        • Validator.php

    Inside Validator.php

    class MyApp_Validate_Validator extends Zend_Validate_Abstract
    {
        //Do stuff here
    }
    

    Now that we have this extra part in the library we need to tell zend that we have a extra namespace with our own code in it

    so in application.ini you configure it like this

    autoloaderNamespaces.0 = MyApp_
    

    Now the application (zend) should know where to look for your validator

    so you can now do the following

    create a form (best to place it in application/forms/ but it’s up to you ofcourse)

    class Form_Register extends Zend_Form {
    
        public function __construct() {
            parent::__construct();
    
            $username = $this->createText('username', 'Gebruikersnaam')
            ->setRequired(true)
            ->addValidator(new MyApp_Validate_Validator());
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have FrameChangeAnimation class which takes multiple spritesheets and duration. So lets say I
I have a class which is : <?php class FileObject{ private $name; private $arr;
I have class which have one public method Start , one private method and
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,
I have class A which extends the Activity class. This class is in package
I have class World which manages creation of object... After creation it calls afterCreation
I have class Employee which is something like this. class Emp { int EmpID;
I have a class which is in charge for error handling. I would like
I have a class which represents exam,it can start/reset/pause exam, so the methods look

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.