Zend Framework simple configuration_PHP tutorial

WBOY
Release: 2016-07-13 10:33:33
Original
857 people have browsed it

Since the project requires the use of the Zend Framework, I will now start to study this framework in depth. The first lesson is always, output Hello World.

Configure the PHP environment where Zend Framework runs

First confirm your PHP environment. Zend Framework requires PHP version to be no lower than 5.1.4, but it is strongly recommended to use 5.2.3 or higher, because there are many major security and performance issues between these two versions. Improve and enhance.

After the 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.

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.

Find the httpd.conf file. If AllowOverride is None, be sure to change None to all, so that files like .htaccess will work if you write them.

Restart your APACHE server so that our PHP environment can use Zend Framewrok.

Configure Zend Framework project

The project folder is as follows:

Zend Framework simple configuration_PHP tutorial

The following introduces the file name and code that need to be modified.

index.php (website entrance) file and description:

<?php
	/*
	 * Date: 2010.11.19
	 * Author:Gonn By www.bkjia.com
	 * Email:gonnsai@163.com
	 * QQ:252211974
	 * Blog:http://www.bkjia.com
	 */
	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 自动载入类文件
	require_once "Zend/Loader/Autoloader.php";
	Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
	$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();
?>
Copy after login

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();
            
    }
    
	/*
	 * 输出Hello World 的Action(动作)!
	 */
	function indexAction() 
    { 
      	//这里给变量赋值,在index.phtml模板里显示
        $this->view->bodyTitle = '<h1>Hello World!</h1>';
		echo $this->view->render('index.phtml');//显示模版  
    } 
}
?>
Copy after login

index.phtml template file description:

<?=$this->bodyTitle; ?><!-- 这里输出控制器里Action传过来的值:hello world -->
Copy after login

Enter: http://localhost/zendframework/ in the browser to output Hello World.

PS: About the error message 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

Zend_Loader::autoload is deprecated starting from version 1.8.0. Zend_Loader::autoload will be removed in version 2.0.0. It is recommended to use Zend_Loader_Autoloader instead of Zend_Loader::autoload.

If

require_once('Zend/Loader.php'); 
Zend_Loader::registerAutoload();
Copy after login

changed to

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

Fatal error: Class 'Templater' not found in /var/www/phpweb20/htdocs/index.php on line 35 will be prompted

I think the class loading failed, because the 'Templater' class is clearly in the path, so the problem should still occur in Zend_Loader_Autoloader.

Just change it to

require_once "Zend/Loader/Autoloader.php";
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
Copy after login

That’s OK!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752464.htmlTechArticleSince the project needs to use the Zend Framework, I will now start to study this framework in depth. The first lesson is always, output Hello World. Configure the PHP environment where Zend Framework runs. First confirm...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template