Posts tagged with php

Yii tag it widget

You can use this widget for tag forms it features autocomplete and and easy way to delete added tags. I use it in combination with the excellent Taggable behavior

Download

Tag it screenshot

Tag it form

read more

Yii slug behavior

Make your url's look pretty, for search engine's and human's :) 

Download

How to use

Just extract the file and drop it in your components directory. I always keep my behaviors seperate but this depends on your structure.

You will need to have two fields in your table, one with the title or name and the second one where you store the slug make this a varchar.

Now add the behavior in your model, rename the title and slug column to the fields in your database

 

/**
 * Model behaviors
 * @return array
 */
public function behaviors() {
	return array(
		'SlugBehavior' => array(
			'class' => 'SlugBehavior',
			'slug_col' => 'slug',
			'title_col' => 'title',
			'overwrite' => false,
		),
	);
}

 

Now if you save the model the slug will be saved automatically.

*It should now work with high utf 8 ranges too like asian characters but I haven't tested all of them. Let me know if you find any issues.

Flexible zend auth adapter

I have been working some more with Zend Framework at work and I needed the Zend_Auth to login users the Zend_Auth_Adapter_Db_Table seems obvious to use only is not very flexible, you cannot use any extra columns in your table to authenticate users.

My solution was to write a Zend_Auth_Db_Select adapter to authenticate against a Zend_Db_Select object so you can write your own query to validate against.

I have also added a way to remember the user and by default only use a session. It did not seem clear from the manual, but Zend_Auth will remember users with a cookie by default. read more

ZF Modular admin routes

This guide will show you how to add a modular strucutre in Zend framework with admin routes, and seperate admin controllers in every module.

Url's will look like:

/module/controller/action

/admin/module/controller/action

Controllers will be seperated:

/modules/blog/PostController.php

/modules/blog/AdminPostController.php

By default Zend Framework does not have any built in option to seperate an application by back and frontend like for example CakePHP has. But it is very easy to add this functionality with some custom routes and a frontcontroller plugin. read more