设为首页 收藏本站
查看: 615|回复: 0

[经验分享] 《PHP Web2.0 开发实战》学习笔记1

[复制链接]

尚未签到

发表于 2017-4-4 06:46:09 | 显示全部楼层 |阅读模式
学习《PHP Web2.0 开发实战》中ZF的使用,刚创建了简单的IndexController类,想看一下效果,结果出现错误:
问题1:
Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in D:\PHPServer\zend\library\Zend\Loader.php on line 266

解决1:
因为从zf2.0开始已经使用 Zend_Loader_Autoloader替代了Zend_Loader,所以需要使用新类,因此index.php中代码修改为

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


问题2:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in D:\PHPServer\zend\library\Zend\Controller\Dispatcher\Standard.php:248 Stack trace: #0 D:\PHPServer\zend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 D:\PHPRoot\phpweb20\htdocs\index.php(10): Zend_Controller_Front->dispatch() #2 {main} thrown in D:\PHPServer\zend\library\Zend\Controller\Dispatcher\Standard.php on line 248

解决2:
这个问题是由于没有默认的错误控制器引起的,代码中增加
$frontController->setParam('useDefaultControllerAlways', true);
控制器会自动寻找与之对应的模型,根据需要的错误中所描述的路径,建立对应的模型。
问题3:
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'index/index.phtml' not found in path (d:/phproot/phpweb20/include/views\scripts/)' in D:\PHPServer\zend\library\Zend\View\Abstract.php:980 Stack trace: #0 D:\PHPServer\zend\library\Zend\View\Abstract.php(876): Zend_View_Abstract->_script('index/index.pht...') #1 D:\PHPServer\zend\library\Zend\Controller\Action\Helper\ViewRenderer.php(897): Zend_View_Abstract->render('index/index.pht...') #2 D:\PHPServer\zend\library\Zend\Controller\Action\Helper\ViewRenderer.php(918): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/index.pht...', NULL) #3 D:\PHPServer\zend\library\Zend\Controller\Action\Helper\ViewRenderer.php(957): Zend_Controller_Action_Helper_ViewRenderer->render() #4 D:\PHPServer\zend\library\Zend\Controller\Action\HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #5 D:\PHPServer\zend\library\Zend\Controller\Action.php(523): Zend_Controller_Action_HelperBroker->notifyPostDispatch() #6 D:\PHPServe in D:\PHPServer\zend\library\Zend\View\Abstract.php on line 980
解决3:使用Zend_Controller时,会自动加载一个名为ViewRenderer的插件,它会根据所请求的控制器和动作名来显示一个视图脚本(模板文件)。而使用Smarty时,必须要扩展Zend_View_Abstrat类从而与Smarty类交互。需要床架一个Templater的类,然后在index.php引导文件中告诉Zend_Controller这个类的信息。
或者根据错误提示创建phpweb20/include/views/scripts/index/index.phtml模板文件,使zf输出时能正常使用。
问题4:
Fatal error: Call to a member function fetch() on a non-object in D:\PHPRoot\phpweb20\include\Templater.php on line 58
解决4:这个错误是因为我根据书中代码录入的时候出现了偏差,类的构造器应该使用两个下划线,而录入时只使用了一个,这就造成templater类没有被正常构造,从而出错。
参考:
1. Uncaught exception 'Zend_Controller_Dispatcher_Exception'http://stackoverflow.com/questions/2130530/uncaught-exception-zend-controller-dispatcher-exception
1. Practical Web 2.0 Applications with PHP – Chapter 2 http://blog.rrosetta.com/2009/10/12/practical-web-2-0-applications-with-php-chapter-2/

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-359795-1-1.html 上篇帖子: [转]PHP与Javascript之间复杂结构数据的传递 下篇帖子: PHP框架Yii系列教程(一):入门实例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表