
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Waanser &#187; CodeIgniter</title>
	<atom:link href="http://www.waanser.com/category/php/framework/codeigniter/feed" rel="self" type="application/rss+xml" />
	<link>http://www.waanser.com</link>
	<description>Un blog utilisant WordPress</description>
	<lastBuildDate>Wed, 07 Jul 2010 21:54:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Plateforme Php: CodeIgniter &amp; Smarty</title>
		<link>http://www.waanser.com/php/framework/codeigniter/255-plateforme-php-partie-1-codeigniter-et-smarty.html</link>
		<comments>http://www.waanser.com/php/framework/codeigniter/255-plateforme-php-partie-1-codeigniter-et-smarty.html#comments</comments>
		<pubDate>Fri, 01 May 2009 22:38:27 +0000</pubDate>
		<dc:creator>tilkc</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://www.waanser.com/?p=255</guid>
		<description><![CDATA[Dans ce tutoriel nous allons donc intégrer Smarty pour CodeIgniter afin de faciliter le développement d&#8217;une application WEB. Installation Nous allons télécharger WampServeur, CodeIgniter et Smarty. Pour WampServeur, suivez les instructions d&#8217;installation. Pour CodeIgniter et Smarty il suffit de dezipper les fichiers. Dans WampServeur nous allons créer notre dossier de base de notre site C:/wamp/www/tutorielwaanser [...]]]></description>
			<content:encoded><![CDATA[<p>Dans ce tutoriel nous allons donc intégrer Smarty pour CodeIgniter afin de faciliter le développement d&#8217;une application WEB.<br />
<span id="more-255"></span></p>
<hr />
<h1>Installation</h1>
<p>Nous allons télécharger WampServeur, CodeIgniter et Smarty.</p>
<p>Pour <a title="Téléchargement de WampServeur" href="http://www.wampserver.com/download.php" target="_blank">WampServeur</a>, suivez les instructions d&#8217;installation.<br />
Pour <a title="Téléchargement de CodeIgniter" href="http://codeigniter.com/downloads/" target="_blank">CodeIgniter</a> et <a title="Téléchargement de Smarty" href="http://www.smarty.net/" target="_blank">Smarty</a> il suffit de dezipper les fichiers.</p>
<p>Dans WampServeur nous allons créer notre dossier de base de notre site<br />
C:/wamp/www/tutorielwaanser</p>
<hr />
<h1>Intégration de Smarty</h1>
<p>Dans le fichier index.php ajouter la constante :<strong> WEBSITE_PATH</strong></p>
<pre class="brush: php">
if (strpos($system_folder, &#039;/&#039;) === FALSE) {

if (function_exists(&#039;realpath&#039;) AND @realpath(dirname(__FILE__)) !== FALSE)
{
$system_folder = realpath(dirname(__FILE__)).&#039;/&#039;.$system_folder;
}
} else {
// Swap directory separators to Unix style for consistency
$system_folder = str_replace(&quot;\\&quot;, &quot;/&quot;, $system_folder);
}

define(&#039;WEBSITE_PATH&#039;, realpath(dirname(__FILE__)).&#039;/&#039;.$application_folder );
</pre>
<p>Dans le fichier <strong>system/application/config/config.php</strong> modifier la variable :</p>
<pre class="brush: php">
$config[&#039;subclass_prefix&#039;] = &#039;WAANSER_&#039;;
</pre>
<p><strong>Créer les arborescences suivantes :<br />
- system/smarty/libs </strong>et copier  les dossiers<strong> Internals et plugins de Smarty</strong><strong><br />
</strong></p>
<p><strong>system/application/smarty/plugins<br />
system/application/smarty/tpl</strong></p>
<p><strong>system/application/tmp/smarty/cache<br />
system/application/tmp/smarty/templates_c</strong></p>
<p>Renommer le fichier <strong>Smarty.class.php en Smarty.php</strong><br />
<strong>Copier les fichier Smarty.php, Smarty_Compiler.class.php et Config_File.class.php</strong> dans le dossier <strong>system/libraries</strong></p>
<hr />Dans le fichier <strong>system/libraries/Smarty.php</strong> couper les constantes et copier les dans le fichier <strong>application/config/constants.php</strong></p>
<pre class="brush: php">
//  ******* Smarty ********
define(&#039;DIR_SEP&#039;, DIRECTORY_SEPARATOR);
define(&#039;SMARTY_DIR&#039;, BASEPATH.&#039;smarty&#039;.DIRECTORY_SEPARATOR);
define(&#039;SMARTY_CORE_DIR&#039;, BASEPATH.&#039;smarty/libs/internals&#039; . DIRECTORY_SEPARATOR);

define(&#039;SMARTY_PHP_PASSTHRU&#039;,   0);
define(&#039;SMARTY_PHP_QUOTE&#039;,      1);
define(&#039;SMARTY_PHP_REMOVE&#039;,     2);
define(&#039;SMARTY_PHP_ALLOW&#039;,      3);
</pre>
<p>Ensuite nous devons créer les libraries <strong>WAANSER_controller</strong> et <strong>WAANSER_smarty </strong>dans le dossier <strong>system\application\libraries</strong></p>
<pre class="brush: php">

class WAANSER_Controller extends Controller {

/**
* @desc	for template
* @var 	obj smarty
*/
public $oMySmarty = null;

public function Controller() {

parent::Controller();

$this-&gt;loadSmarty();
}

public function loadSmarty() {

$this-&gt;oMySmarty = &amp;amp;amp;amp;amp;amp;load_class(&#039;Smarty&#039;);
}

}
</pre>
<p>Ce fichier va nous permettre d&#8217;étendre le contrôleur d&#8217;origine, pour récupérer tous le processus de chargement des classes, et nous ajoutons un attribut $oMySmarty qui sera un objet de la classe Smarty.</p>
<p>Avec cet objet on pourra changer de générateur de template.<br />
On peut, même si c&#8217;est moche <img src='http://www.waanser.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   utiliser le générateur de templates par défaut en même temps que le générateur Smarty.</p>
<pre class="brush: php">

class WAANSER_Smarty extends Smarty {

/**
* @desc	class constructor
* @version	1.0.0
* @date	20090307
*/
public function __construct() {

parent::Smarty();
$this-&gt;setParams();
}

/**
* @desc 	initialise les variables pour smarty
* @version 1.0.0
* @date	20090307
*/

public function setParams() {
$this-&gt;template_dir = APPPATH.&#039;smarty/tpl&#039;;
$this-&gt;compile_dir = APPPATH.&#039;tmp/smarty/templates_c&#039;;
$this-&gt;plugins_dir = array(APPPATH.&#039;smarty/libs/plugins&#039;, APPPATH.&#039;smarty/plugins&#039;);
}

}

?&gt;
</pre>
<p>Il nous reste a changer le fichier welcome dans le dossier <strong>system\application\controllers</strong>, il suffit juste de changer l&#8217;appel au fichier parent.</p>
<pre class="brush: php">

class Welcome extends WAANSER_Controller {

function Welcome()
{
parent::Controller();
}

function index()
{
$this-&gt;oMySmarty-&gt;assign(&#039;TEST_WAANSER&#039;, &#039;Smarty est OK&#039;);
$this-&gt;oMySmarty-&gt;display(&#039;welcome.tpl&#039;);
//$this-&gt;load-&gt;view(&#039;welcome_message&#039;);
}
}
</pre>
<p>Et de lui ajouter une variable avec la methode <strong>assign </strong>et de lui indiquer le template a afficher avec la methode <strong>display</strong>.</p>
<p>Ensuite ajouter le fichier <strong>welcome.tpl</strong> dans le dossier <strong>system\application\smarty\tpl</strong></p>
<pre class="brush: php">

&lt;p&gt;{$TEST_WAANSER}&lt;/p&gt;
</pre>
<p>Au prochain Tuto <img src='http://www.waanser.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.waanser.com/php/framework/codeigniter/255-plateforme-php-partie-1-codeigniter-et-smarty.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
