MySQL can be used to do some string replacements rather using any programming languages.
The following is used to replace space with hyphen in list names
UPDATE list SET list_name = REPLACE(list_name, ' ', '-') WHERE list_name LIKE '% %';
User registration form is a good example for this validator. Checking the username exists or not.
Db_NoRecordExists validator helps to achieve this
$username = new Zend_Form_Element_Text('username',
array('label' => 'Username',
'required' => true,
'filters' => array('StripTags', 'StringTrim'),
'validators' => array('NotEmpty', array('Db_NoRecordExists',false,array(
'users_table','username_column', 'messages' => array( Zend_Validate_Db_Abstract::ERROR_RECORD_FOUND => '%value% already exists')
)))));
If your Putty Connection Manager doesn't load Putty inside the Manager then do this :
1. Go to View -> Connection Manager
2. Right Click in side the right panel -> create a Database ( give any name )
That will create SSH and Telnet folders
3. Right Click on SSH folder and then New -> Connection Manager
4. Add Host Name and select SSH protocol
5. File -> Save All Databases
You are done now.
System commands can be executed from PHP using exec command.
eg:
$out = array(); $command = "memcat --server=10.10.10.10 ITEMS > /tmp/items.txt";The $out variable would hold the output of the command. If there is any issue with executing a command , have the command with path.
exec($command, $out);
eg: $command = "/usr/local/bin/memcat --server=10.10.10.10 ITEMS > /tmp/items.txt";for further info: http://www.php.net/manual/en/function.exec.php
exec($command, $out);
Like keyword can be used with Zend_Db select query
$query = $this->select()
->where("firstname like ?", $letter."%");
try that works.
There is a way to select comma separated data from any mysql table.
SELECT poll_id,group_concat(option_id) FROM `poll_elements`
group by poll_id
this will output as follows:
poll_id | group_concat(option_id)
1 | 3855,5098,8474
3 | 3855,9469,15677
6 | 509,3855,9469,10489
If the hidden field added to the Zend form leaves extra space between elements, remove those tags around it.
$this->addElement("hidden", "id",
array('disableLoadDefaultDecorators' => true));
That will do it.
This is the way to select records from tables of different databases
SELECT * FROM `db`.table tb
INNER JOIN `db2`.table2 tb2 ON tb2.id = tb.id
hope it helps someone.
Custom error messages can be added to a form element:
The following shows how to add custom error message to a select element
$countryList = array("0" => "select" ,"1" => "Canada", "2" => "India", "3" => "America");
$countries = new Zend_Form_Element_Select('country');
$countries->setLabel("Country")
->setRequired(true)
->addFilter('Int')
->addMultiOptions($countryList)
->addValidator('GreaterThan',false, array("min"=>1, "messages" => array("notGreaterThan"=>"country is required")));
validator name = GreaterThan
message for = notGreaterThan ( get it from validator library file or api doc)
The customr error message will display now.
Merge two arrays together using array_merge function
$result = array_merge(array(0=>"Hello"), array(3=>"World"));
The result will have an array with keys got re-numbered
therefore the key 3 will be changed to 1.
If you want to keep your array keys unchanged
$result = $arr1 + $arr2;
That will do it.
A text element of a form can be made read only therefore user cannot touch the value
$this->addElement('text','current_date',array(
'attribs' => array('readonly' => 'true')));
that will do it.
If you happened to select records in key value pair, try this way
$query = $this->select()
->from($this->_name, array('id', 'name'));
$this->getAdapter()->fetchPairs($query);
that will return
222 => "Velvom"
If any chance to do an UPDATE on the same table, here is the SQL for that
UPDATE my_list AS a
INNER JOIN my_list AS b
ON a.id = b.id
SET a.list_name_val = md5( b.list_name )
the above SQL will update list_name_val column with md5 of list_name.
If you'd like to let visitors select their language on your site, do the following in your index.php file
$lang_request = JRequest::getWord('lang');
$lang_choice = implode("-", str_split($lang_request, 2));
$currentSession = JFactory::getSession();
if(!empty($lang_choice))
{
$currentSession->set("langChoice",$lang_choice);
$lang =& JFactory::getLanguage();
$lang->setLanguage( $lang_choice );
$lang->load();
}
elseif($currentSession->getState())
{
$lang =& JFactory::getLanguage();
$lang->setLanguage( $currentSession->get("langChoice") );
$lang->load();
}
when user clicks on a link have your url like the following:
http://www.yoursite.com/?lang=de-DE or /?lang=en-GB
the lang would be stored in session so you don't need to worry about it anymore.
To display SQL of Zend_Db_Select object, try this
$query = $this->select()
->where("permitted = 'Y'")
->order("id DESC")
->limit($count);
echo $query->__toString();
that will do it.
If you like to add 'Select Category' option to the option list you got from DB.
$db =& JFactory::getDBO();
$query = "SELECT id as value,name as text FROM categories WHERE parent_id > 0 ORDER BY name";
$db->setQuery($query);
$categories = $db->loadAssocList();
$begin_categories = array(array("value"=>0,"text"=>"Select Category"));
$categories = array_merge($begin_categories,$categories);
$lists['categories'] = JHTML::_('select.genericlist', $categories, 'categories', 'class="inputbox" size="1"', 'value', 'text', null);
I am not sure any better way to do with Joomla classes.
The Joomla 1.5 is coming with Mootools therefore you might experience some conflict with jQuery now.
Just follow the way below to avoid any conflicts. Add the following lines to your view.html.php.
$document = &JFactory::getDocument();
$document->addScript( 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' );
$document->addCustomTag( '' );
The above code fragment would solve your problem.
How to add Javascript or css to your Joomla template?
Just do the following to get it working. Add the following lines to your view.html.php.
$document = &JFactory::getDocument();
$this->document->addStyleSheet('your path/style.css');
$this->document->addScript( 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' );
That would solve your problem.
This is how you add a calendar / date picker to Joomla form.
add the following code to your
xx.html.php class
$document = &JFactory::getDocument();
$document->addScript("includes/js/joomla.javascript.js");
JHTML::_('behavior.calendar');
and add the following code to the default.php template file
All those codes above will have a calendar / date picker close to the input field.
Enjoy your coding.