yii, recursive function to create category sub category hierarchy

Create this function in the category model file: ———————————————————————————  <?phppublic function get_category_hr($cat_id, $selected_cat_id, $level_string) { $select_str=”; if(!$level_string) { $level_string=”; } if ($cat_arr = $this->findAll(‘category_parent_id=’ . $cat_id)) { foreach ($cat_arr as $cat) { $select_str.=”<option value={$cat->category_id}”; if($selected_cat_id==$cat->category_id) $select_str.= ‘ selected’; $select_str.=”>{$level_string}{$cat->category_name}</option>”; $select_str.= $this->get_category_hr($cat->category_id, $selected_cat_id, $level_string.’+’); } } else { return false; } return $select_str; }?>  Call this… Continue reading yii, recursive function to create category sub category hierarchy

php recursive fucntion to get categories and subcategories

Here is my simple recursive function to create a category subcategory tree of unlimited subcategories. <select name=”parent_cat”> <option value=”0″>Root</option> <? function get_all_sub_cats($parent_cat_id, $level_string) { $return_str=”; if(!$level_string) { $level_string=”; } $db=new DB(); $db->open(); $db->query(“select * from categories where parent_id='{$parent_cat_id}'”); $db->rsset(); if($db->rs) { while($db->rs) { $return_str.=”<option value=”{$db->rs[‘id’]}” style=”padding-left:10px”>{$level_string}{$db->rs[‘name’]}</option>”; $return_str.=get_all_sub_cats($db->rs[‘id’], $level_string.’+’); $db->rsset(); } } else { return false;… Continue reading php recursive fucntion to get categories and subcategories

Published
Categorized as php

yii, How to automate timestamps in ActiveRecord models

There are many ways to automate the setting of timestamps in yii ActiveRecord models. Two of them are: Via rules() Via beforeSave() To start off we need to create a database table. CREATE TABLE IF NOT EXISTS `Nodes` ( `id` bigint(20) NOT NULL auto_increment, `title` varchar(255) NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT… Continue reading yii, How to automate timestamps in ActiveRecord models

yii, Organize directories for applications with front-end and back-end

Large applications are often divided into front-end and back-end (or even more ends) depending on the target user groups. The front-end should be used by common users, while the back-end mainly the administrators or staff members. The two ends usually have dramatically different appearance, even though they may share a lot of code underneath. In… Continue reading yii, Organize directories for applications with front-end and back-end

yii, easy and simple user role management using yii’s AuthManager

Step 1 :  Create table : CREATE TABLE User( `id` INT(11) NOT NULL AUTO_INCREMENT,`username` VARCHAR(45),`password` VARCHAR(254),`title` VARCHAR(45),PRIMARY KEY(`id`))ENGINE = MyISAM; Step 2 : Add following code in config/main.php ‘authManager’=>array( ‘class’=>’CDbAuthManager’, ‘defaultRoles’=>array(‘authenticated’, ‘guest’), ), Below this code ‘db’=>array( ‘connectionString’ => ‘mysql:host=localhost;dbname=comocomo’, ’emulatePrepare’ => true, ‘username’ => ‘root’, ‘password’ => ‘abc123’, ‘charset’ => ‘utf8’, ), Step 3:… Continue reading yii, easy and simple user role management using yii’s AuthManager