Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Fernando www.fernyb.net

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Automating Zend MVC Structure

Automating Zend MVC Structure
This is what I use... It's very useful.


   1  
   2  <?php
   3  #
   4  # Automate the creation of the Zend MVC Framework
   5  # Script Written by: Fernando Barajas
   6  # Usage: php ./zendcreate.php
   7  #
   8  
   9  # Create the Zend MVC Framework.
  10  define('ZEND_FILE_TYPE', '.tar.gz');
  11  define('ZEND_FILE_NAME', 'ZendFramework-1.5.0'. ZEND_FILE_TYPE);
  12  define('ZEND_FRAMEWORK_URL', 'http://framework.zend.com/releases/ZendFramework-1.5.0/'. ZEND_FILE_NAME);
  13  define('APPLICATION_NAME', 'zend_'. time());
  14  
  15  
  16  passthru("wget ". ZEND_FRAMEWORK_URL);
  17  
  18  
  19  if(file_exists(ZEND_FILE_NAME)) {
  20  	# unzip the file -- tar zxvf ./ZEND_FILE_NAME
  21  	passthru("tar zxvf ". ZEND_FILE_NAME);
  22  	
  23  	# Make the Applications Directories
  24  	passthru("mkdir ". APPLICATION_NAME);
  25  	
  26  	# Move the Library directory into the application directory
  27  	passthru("mv ./". basename(ZEND_FILE_NAME, ZEND_FILE_TYPE) ."/library ./". APPLICATION_NAME ."/library");
  28  	
  29  	# Make the App Directory 
  30  	passthru("mkdir ". APPLICATION_NAME ."/app");
  31  	
  32  		passthru("mkdir ". APPLICATION_NAME ."/app/controllers");
  33  		passthru("mkdir ". APPLICATION_NAME ."/app/models");
  34  		passthru("mkdir ". APPLICATION_NAME ."/app/views");
  35  			
  36  			passthru("mkdir ". APPLICATION_NAME ."/app/views/scripts");
  37  			
  38  	
  39  	# Make the public Directory
  40  	passthru("mkdir ". APPLICATION_NAME ."/public");
  41  	
  42  	# Make the Front Controller / Bootstrap file
  43  $zend_bootstrap_code = '
  44  <?php
  45  # Set Error Reporting
  46  error_reporting(E_ALL|E_STRICT);
  47  ini_set(\'display_errors\', \'on\');
  48  
  49  # Set include path the DOCUMENT_ROOT / library for Zend Library
  50  ini_set(\'include_path\', $_SERVER[\'DOCUMENT_ROOT\']."/../library");
  51  
  52  # Zend Framework Includes
  53  require_once \'Zend/Loader.php\';
  54  
  55  Zend_Loader::loadClass(\'Zend_Controller_Front\');
  56  
  57  # Un-Comment the two lines below if you will be using Routes
  58  # Most likely you will be. I recommend that you do. 
  59  # They are very useful
  60  #
  61  # Zend_Loader::loadClass(\'Zend_Controller_Router_Rewrite\');
  62  # Zend_Loader::loadClass(\'Zend_Controller_Router_Route_Regex\');
  63  #
  64  
  65  # Get the front controller instance
  66  $front = Zend_Controller_Front::getInstance();
  67  $front->setControllerDirectory("../app/controllers");
  68  
  69  $front->throwExceptions(true);
  70  
  71  #
  72  # Get an Instance For Routing
  73  # $route = $front->getRouter(); // Returns a rewrite router by default
  74  # $route->addRoute(\'user\',
  75  #	new Zend_Controller_Router_Route(\'user/:username\', array(\'controller\' => \'index\', \'action\' => \'test\'))
  76  # );
  77  #
  78  # $route->addRoute(\'product\',
  79  #	new Zend_Controller_Router_Route_Regex(\'product/(\d+)\', array(\'controller\' => \'index\', \'action\' => \'test\'))
  80  # );
  81  #
  82  # $route->addRoute(\'login\',
  83  #	new Zend_Controller_Router_Route_Regex(\'login\', array(\'controller\' => \'index\', \'action\' => \'test\'))
  84  # );
  85  #
  86  
  87  # Start the dispatch
  88  $front->dispatch();
  89  
  90  ?>
  91  ';
  92  	# Write the Bootstrap file
  93  	file_put_contents("./". APPLICATION_NAME ."/public/index.php", trim($zend_bootstrap_code));
  94  	
  95  # Write The Index Controller
  96  $zend_index_controller_code = '
  97  <?php
  98  
  99  class IndexController extends Zend_Controller_Action {
 100  
 101  	public function indexAction() {
 102  		# => Logic code here...
 103  		$this->view->random_number = rand(0,10);
 104  		$this->view->status = "It works!";
 105  		$this->render("index");
 106  	}
 107  }
 108  
 109  ?>
 110  ';
 111  	# Write the First Index Controller
 112  	file_put_contents("./". APPLICATION_NAME ."/app/controllers/IndexController.php", trim($zend_index_controller_code));
 113  
 114  
 115  # Write the index view file
 116  $zend_index_view_code = '
 117  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 118  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 119  <head>
 120    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
 121    <title>Zend Framework</title>
 122  </head>
 123  <body>
 124  <h2>Status: <?= $this->status ?></h2>
 125  <div>
 126  	Random Number: <?= $this->random_number ?>
 127  </div>
 128  </body>
 129  </html>
 130  ';
 131  	# Write the First Index View File
 132  	passthru("mkdir ./". APPLICATION_NAME ."/app/views/scripts/index");
 133  	file_put_contents("./". APPLICATION_NAME ."/app/views/scripts/index/index.phtml", $zend_index_view_code);
 134  	
 135  	
 136  # Create the .htaccess file
 137  $zend_htaccess_code = '
 138  RewriteEngine On
 139  RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
 140  ';
 141  	# Write the .htaccess code to disk
 142  	file_put_contents("./". APPLICATION_NAME ."/public/.htaccess", trim($zend_htaccess_code));
 143  	
 144  	
 145  	# Delete the Downloaded Framework Directory and tar file
 146  	passthru("rm -f ./". ZEND_FILE_NAME);
 147  	passthru("rm -rf ./". basename(ZEND_FILE_NAME, ZEND_FILE_TYPE));
 148  	
 149  	passthru("clear");
 150  	
 151  	echo "\nZend Framework has been created... Done!\n\n";
 152  }
 153  
 154  ?>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS