This article describes the environment configuration for getting started with Zend Framework and the first example Hello World program. Share it with everyone for your reference, the details are as follows:
Step one: Confirm your PHP environment:
1. Please PHPer confirm whether your PHP version is above 5.2.0. If not, please update to 5.2.0, otherwise, Zend Framework seems to be unusable. I have tried it myself.
I have encountered such a problem..So please test it yourself..The download address of the latest version of PHP source code is: http://www.php.net/downloads.php.
2. After your PHP environment is configured, please open the php.ini file and confirm whether the PDO extension is turned on. If not, please remove the ; sign before extension=php_pdo.dll.
3. Open the httpd.conf file in the APACHE folder. Find the mod_rewrite module of apache and confirm whether LoadModule rewrite_module modules/mod_rewrite.so is open. If not, please remove the # sign in front of it.
4. Find the httpd.conf file. If AllowOverride is None... please be sure to change None to all. Only then will files like .htaccess work if you write them...
5. Restart your APACHE server.. This way our PHP environment can use Zend Framewrok.
Step 2: Obtain Zend Framework source code:
1. Download the latest version of Zend Framework source code. The latest version seems to be 1.7.0 now. But it is afraid of instability. So PHPers are asked to decide which version to use.
You can download the source code of the latest version from http://www.zendframework.com/download/latest.
Step 3: Create project directory:
I don’t want to say anything more..I will show you the picture..It is my project directory for this tutorial...I have explained it above..You can create the directory in the following way.. Of course, I will provide the source code for download below.
However, I suggest that friends must do it themselves... so that they can learn more. I also provide the source code just as a reference for everyone.
Step 4: Procedure Description:
I won’t say much here. Because there are comments in each file. I think it won’t be too difficult. If some friends don’t understand, please leave me a message on the blog. I will follow this blog and try to answer as much as possible. Your question..Thank you..
index.php (website entrance) file and description:
<?php error_reporting(E_ALL|E_STRICT); date_default_timezone_set('Asia/Shanghai'); set_include_path('.' .PATH_SEPARATOR .'./library' .PATH_SEPARATOR .'./application/models/'.PATH_SEPARATOR .get_include_path()); require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); //设置Zend Framework 自动载入类文件 $registry = Zend_Registry::getInstance(); //设置模板显示路径 $view = new Zend_View(); $view->setScriptPath('./application/views/scripts/'); $registry['view'] = $view;//注册View //设置控制器 $frontController =Zend_Controller_Front::getInstance(); $frontController->setBaseUrl('/zendframework')//设置基本路径 ->setParam('noViewRenderer', true) ->setControllerDirectory('./application/controllers') ->throwExceptions(true) ->dispatch();
IndexController.php file and description:
<?php class IndexController extends Zend_Controller_Action { function init() { $this->registry = Zend_Registry::getInstance(); $this->view = $this->registry['view']; $this->view->baseUrl = $this->_request->getBaseUrl(); } function indexAction() { //这里给变量赋值,在index.phtml模板里显示 $this->view->bodyTitle = '<h1>Hello World!</h1>'; echo $this->view->render('index.phtml');//显示模版 } }
index.phtml template file description:
<?=$this->bodyTitle; ?> <!-- 这里输出控制器里Action传过来的值:hello world -->
Click here to download the complete example code from this website.
However, Zend is not included in my library. Please add it yourself as a PHPer. If you have any questions, please leave me a message.
Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP programming based on the Zend Framework framework.