changed
Title
Use phing to makeourYii application "installable"
Use phing to makeourYii application "installable"
To use this "how-to", you need to install [phing](http://www.phing.info/trac/ "phing") in your machine. I want to show you a little example thatallowallows me to configure gii password and database informations, with phing. First of all, when I start a new yii application, I copy protected/config/main.php inprotected/config/main.php.dist,protected/config/main.php.dist and updating some fieldlike ...:like: ~~~ [php]'db''db' => array('connectionString' => 'mysql:host=[[hostname]];dbname=[[database]]', 'emulatePrepare''emulatePrepare' => true,'username''connectionString' => 'mysql:host=[[hostname]];dbname=[[database]]', 'username' => '[[username]]','password''password' => '[[password]]','charset''charset' => 'utf8',),), ~~~IAlso, I likealsoto set gii configuration in this way: ~~~ [php]'gii''gii' => array('class''class' => 'system.gii.GiiModule','password''password' => '[[giipassword]]','ipFilters''ipFilters' => array('127.0.0.1', '::1'),),), ~~~Now, myMy complete config(.dist) file looks like this: ~~~ [php] <?php return array( 'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..', 'name' => 'YiiApp', 'preload' => array( 'log' ), 'import' => array( 'application.models.*', 'application.components.*', ), 'modules' => array( 'gii' => array( 'class' => 'system.gii.GiiModule', 'password' => '[[giipassword]]', 'ipFilters' => array('127.0.0.1', '::1'), ), ), 'components' => array( 'user' => array( 'allowAutoLogin' => true, ), 'db' => array( 'connectionString' => 'mysql:host=[[hostname]];dbname=[[database]]', 'emulatePrepare' => true, 'username' => '[[username]]', 'password' => '[[password]]', 'charset' => 'utf8', ), 'errorHandler' => array( 'errorAction' => 'site/error', ), 'log' => array( 'class' => 'CLogRouter', 'routes' => array( array( 'class' => 'CFileLogRoute', 'levels' => 'error, warning', ), ), ), ), 'params' => array( 'adminEmail' => 'webmaster@example.com', ), ); ~~~ Now I can create build.xml and put it inside this content: ~~~ [xml] <?xml version="1.0" encoding="UTF-8"?> <project name="MyYiiApp" default="database"> <target name="database" description="Configure database"> <input propertyname="hostname" defaultValue="127.0.0.1" promptChar="?">Enter the hostname of db.</input> <input propertyname="database" defaultValue="database" promptChar="?">Enter the name of db.</input> <input propertyname="username" defaultValue="root" promptChar="?">Enter username to access to the db.</input> <input propertyname="password" defaultValue="root" promptChar="?">Enter password to access to the db.</input> <input propertyname="giipassword" defaultValue="giipassword" promptChar="?">Enter password to access to gii.</input> <copy file="protected/config/main.php.dist" tofile="protected/config/main.php" overwrite="true"> <filterchain> <replacetokens begintoken="[[" endtoken="]]"> <token key="hostname" value="${hostname}" /> <token key="database" value="${database}" /> <token key="username" value="${username}" /> <token key="password" value="${password}" /> <token key="giipassword" value="${giipassword}" /> </replacetokens> </filterchain> </copy> </target> </project> ~~~ And now, I can run ~~~ $ phing ~~~ The output will be similar to this: ~~~ [php] Buildfile: /var/www/yiiapp/build.xml: Enter the hostname of db. [127.0.0.1]? Enter the name of db. [database]? yiiapp Enter username to access to the db. [root]? Enter password to access to the db. [root]? Enter password to access to gii. [password]? [copy] Copying 1 file to /var/www/yiiapp/protected/config [copy] Copying 1 file to /var/www/yiiapp/protected/config BUILD FINISHED ~~~ As you can see, some questions will beasket toasked from you. Your answers willbeoverride main.php.dist file options when copying itintoto main.php.AndThis is just a simple example of how you can install your applicationinusing thiseasy way. This is just a simple example.method. You can also, for example, create your own console command and call them with phing.