Billets de la catégorie : CodeIgniter

Collection de wallpapers sur le thème de CodeIgniter

Posté par Kromack le 17 février 2010 à 13:05 dans CodeIgniter   
Réagir à ce billet | Ce billet à été lu 102 fois

Êtes-vous de vrai fans de CodeIgniter ?

Si oui, cette collection de fond d’écrans de CodeIgniter devrait vous ravir !

Il s’agit de la page de CodeIgnitEE sur tumblr qui propose une sélection de fond d’écrans de notre framework préféré, et ça se passe par ici !

wallpaper codeigniter

Tutoriel Acicrud : ajouter des custom methods à vos modèles

Posté par Kromack le 10 janvier 2010 à 19:48 dans CodeIgniter   
Réagir à ce billet | Ce billet à été lu 223 fois

Tutoriel ACICRUD #5

Dans ce cinquième tutoriel d’utilisation de la librairie ACICURD pour CodeIgniter, nous allons voir comment définir de nouvelles méthodes dans les modèles utilisant ACICRUD et comment profiter de certaines méthodes de la librairie.

Création d’une méthode spécifique

Imaginons que vous désiriez sélectionner un champ username dans une table user à partir de l’identifiant de l’utilisateur id. Nous allons pour cela ajouter une nouvelle méthode dans notre modèle ayant exactement le fonctionnement que nous désirons et s’appuyant sur la méthode $this->row() qui exécute la requête Active Record et retourne un objet résultat.

Notez qu’il serait également possible d’utiliser la méthode getAll() d’ACICRUD pour arriver à ce résultat.

Voici le code du fichier user.php à placer dans le répertoire models :

<?php
 
class User extends Acicrud {
 
	//CONSTRUCTOR
	public function __construct()
	{
		parent::__construct('user');
	}
 
	//CUSTOM METHODS
 
	/**
	 * Return the username of an user identified by his id
	 *
	 * @param int $id
	 * @return Object
	 */
	public function get_username($id = null) {
 
		try {
 
			// Checking if $id is a valid primary key value
			$this->checkId($id);
 
			// Building the query
			$this->db->select('username')->from($this->table)->where($this->key, $id);
 
			// Returning the result
			return $this->row();		
 
		} catch(Exception $e) {
 
			throw($e); // Throws the ACICRUD's exception
 
		}
	}
 
}
 
?>

Il vous est donc tout à fait possible d’ajouter vos propres comportements au sein d’un modèle héritant de la librairie ACICRUD. Notez que dans cet exemple, la méthode s’appuie également sur le système d’exceptions géré par ACICRUD. Je vous conseille donc d’inclure l’appel de la méthode get_username dans votre contrôleur au sein d’un bloc try/catch.

Soutenez CodeIgniter en ajoutant un Twibbon à votre avatar !

Posté par Kromack le 10 janvier 2010 à 13:57 dans CodeIgniter   
Réagir à ce billet | Ce billet à été lu 847 fois

Supportez dès aujourd’hui le framework PHP CodeIgniter sur le réseau Twitter en ajoutant un Twibbon à votre avatar !

L’application Twibbon permet d’ajouter en un clic, un logo sur l’avatar de votre profil Twitter sans avoir à faire la moindre manipulation !

N’ttandez-plus et rejoignez-nous !

Ajouter un Twibbon CodeIgniter.

CKEditor Helper for CodeIgniter

Posté par Kromack le 2 janvier 2010 à 18:36 dans CodeIgniter   
10 Commentaires | Ce billet à été lu 2 225 fois

Using CKEditor as a plugin in your CodeIgniter applications

CKEditor is a powerfull WYSIWYG text editor licensed under the GPL, LGPL and MPL open source licenses. CKEditor can easilly be added to any web page, you will find below a simple way to integrate CKeditor to your CodeIgniter applications.

Downloading CKEditor

The first step is to download the CKEditor editor package, note that the helper have only be tested over CKEditor 3.0.2. Once done, you should consider to remove the _samples and _sources directories from the uncompressed files.

Then, place the entire ckeditor directory into a /js/ folder. You can place it anywhere but remember to set the correct path when initializing the helper.

Adding the CKEditor helper for CodeIgniter

Download and place the ckeditor_helper.php file into the CodeIgniter’s system/application/helpers folder.

This helper can, for the moment, manage all CKEditor’s available configuration options and custom styles definitions.

Creating the controller

First of all, we are going to create a controller that will set all the helper’s configuration options. You are able to set all CKEditor’s available configuration options inside the config array. We are also going to define two custom styles to replace the CKEditor’s default styles. Note that the id must match the textarea’s id in the view.

<?php
 
class Ckeditor extends Controller {
 
	public $data 	= 	array();
 
	public function __construct() {
 
		parent::Controller();
 
		$this->load->helper('url'); //You should autoload this one ;)
		$this->load->helper('ckeditor');
 
		//Ckeditor's configuration
		$this->data['ckeditor'] = array(
 
			//ID of the textarea that will be replaced
			'id' 	=> 	'content', 	// Must match the textarea's id
			'path'	=>	'js/ckeditor',	// Path to the ckeditor folder relative to index.php
 
			//Optionnal values
			'config' => array(
				'toolbar' 	=> 	"Full", 	//Using the Full toolbar
				'width' 	=> 	"550px",	//Setting a custom width
				'height' 	=> 	'100px',	//Setting a custom height
 
			),
 
			//Replacing styles from the "Styles tool"
			'styles' => array(
 
				//Creating a new style named "style 1"
				'style 1' => array (
					'name' 		=> 	'Blue Title',
					'element' 	=> 	'h2',
					'styles' => array(
						'color' 		=> 	'Blue',
						'font-weight' 		=> 	'bold'
					)
				),
 
				//Creating a new style named "style 2"
				'style 2' => array (
					'name' 		=> 	'Red Title',
					'element' 	=> 	'h2',
					'styles' => array(
						'color' 		=> 	'Red',
						'font-weight' 		=> 	'bold',
						'text-decoration'	=> 	'underline'
					)
				)				
			)
		);
 
 
	}
 
	public function index() {
 
		$this->load->view('ckeditor', $this->data);
 
	}
}

Creating the view

The ckeditor.php view only has to display a textarea element with the matched id and call the display_ckeditor() helper’s function.

<textarea name="content" id="content" ><p>Example data</p></textarea>
<?php echo display_ckeditor($ckeditor); ?>

That’s all ! If you’ve followed all the steps correctly, CKEditor should shows up in the view. Please note that I assume that you are loading also a correct header and footer view with all the xHTML required stuff.

Downloading the tutorial

Source files of this tutorial (controller, helper, and view) can be downloaded here.

Changelog

  • 2010-01-12: All the stuff moved out of system/plugins.
  • 2010-01-30: Fixed Internet Explorer compatibility issue.

Troubleshooting

  • If you are using the .htaccess file given by the CodeIgniter’s user guide and have placed the ckeditor’s folder into system/plugins, be sure to allow the directory system to be called via HTTP in order to allow access to the plugins directory

Licence

Creative Commons License
CKEditor plugin for CodeIgniter by Samuel Sanchez is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.
Based on a work at codeigniter.com.
Permissions beyond the scope of this license may be available at http://www.kromack.com/contact-kromack-developpeur-france/.

Please note that this helper is based on an original idea discussed in this CodeIgniter thread.