GENWiki

Premier IT Outsourcing and Support Services within the UK

User Tools

Site Tools


joomla:create_or_edit_a_category_in_php

To create (or if exists update) a category in Joomla via PHP…

    $ip="217.36.11.28";
    $ipf=JFilterOutput::stringURLSafe($ip);
    $cat = JTable::getInstance('category');
    $cat->load(array('alias'=>$ipf));
 
    if ($cat->id==null) {
    	echo "Create Category<br>";
    	$cat->parent_id=13;
    	 $cat->level=2;
    	 $cat->extension='com_content';
    	 $cat->published=1;
    	 $cat->access=1;
    	 $cat->language='*';
    	 $cat->path="tool-processing-reports/".$ipf;
    	$cat->title='Blacklist for 217.36.11.28';
    	$cat->alias='217-36-11-28';
    	if (!$cat->check()) { 
    		JError::raiseNotice(500, $cat->getError());
    		 echo "Category Check failed<br>";
    	} else {
    		if (!$cat->store(TRUE)) { 
    			JError::raiseNotice(500, $cat->getError()); 
    			echo "Category Create Failed<br>";
    		} else {
    			echo "Category Created<br>";
    		}
    	}
 
    } else {
    	echo "Update Category<br>";
    }

Richard 2019/03/21 11:22

/data/webs/external/dokuwiki/data/pages/joomla/create_or_edit_a_category_in_php.txt · Last modified: 2019/05/20 09:03 by genadmin

Was this page helpful?-13+1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki