1
我在Zend框架中實現表單時遇到了問題1.我在application/forms/CustomForm.php中添加了表單。它看起來像這樣。Zend表格自動加載
class CustomForm extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$id = $this->createElement('hidden','id');
$firstname = $this->createElement('text','firstname');
$firstname->setLabel('First Name:')
->setAttrib('size',50);
$lastname = $this->createElement('text','lastname');
$lastname->setLabel('Last Name:')
->setAttrib('size',50);
$username = $this->createElement('text','username');
$username->setLabel('Username:')
->setAttrib('size',50);
$email = $this->createElement('text','email');
$email->setLabel('Email:')
->setAttrib('size',50);
$password = $this->createElement('password','password');
$password->setLabel('Password:')
->setAttrib('size',50);
$password2 = $this->createElement('password','password2');
$password2->setLabel('Confirm Password::')
->setAttrib('size',50);
$register = $this->createElement('submit','register');
$register->setLabel("Register")
->setIgnore(true);
$this->addElements(array(
$firstname,
$lastname,
$username,
$email,
$password,
$password2,
$id,
$register
));
}
}
,包括在index.php文件看起來像這樣
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../application'),
realpath(APPLICATION_PATH . '/../application/forms'),
)));
但是,當我打電話$form = new CustomForm();
,在usercontroller.php,我得到這個「致命錯誤路徑:類‘CustomForm’未找到在250行的/var/www/demoapp/application/controllers/UserController.php「。可能是什麼問題?
'的var_dump(真實路徑(APPLICATION_PATH '/../應用/表格'));'並仔細檢查,這是你所期望的。 – mkaatman
雅路徑是正確的,我得到這個字符串(37)「/ var/www/demoapp/application/forms」 – Ninju
哦,等等,我看到發生了什麼。您正試圖自動加載它。 set_include_path設置可用的路徑,但您仍然需要包含/需要這些文件。你可能想要做的是設置自動加載。 http://framework.zend.com/manual/1.12/en/zend.loader.autoloader.html – mkaatman