jQuery(document).ajaxComplete(function(e, xhr, settings){
var d = document.location.pathname + document.location.search + document.location.hash;
_gaq.push(['_trackPageview', d]);
});
Source: http://stackoverflow.com/questions/7737549/google-analytics-and-loading-a-page-using-ajax-get-request
Friday, November 16, 2012
Add AJAX Request to Google Analytics
If you use jQuery you can bind to the global AjaxComplete event to fire a Pageview everytime an Ajax call completes:
Sunday, October 28, 2012
FreeTDS Output Parameter Not Return to PHP
I had a stored procedure that returned with the output parameter (I found it in the FreeTDS log file) but the variable of the output parameter was blank in PHP.
I checked the stored procedure and I found a stupid 'select @foo' selection in the procedure, before the initialization of the output parameter (set @output='bar').
I commented the selection (--select @foo) and now it works like a charm, the value of ouput parameter is available in the output PHP variable.
I hope this helps you.
Tuesday, October 16, 2012
Native SQL Query in Doctrine
Examples...
// get Doctrine_Connection object
$con = Doctrine_Manager::getInstance()->connection();
// execute SQL query, receive Doctrine_Connection_Statement
$st = $con->execute("...............");
// fetch query result
$result = $st->fetchAll();
Or with parameter...
$db = Doctrine_Manager::getInstance()->connection();
$query = $db->prepare("INSERT INTO search_term (term, counter) VALUES (:term, '1') ON DUPLICATE KEY UPDATE counter=counter+1;");
$query->execute(array('term' => $search));
Labels:
doctrine,
doctrine orm,
mysql,
native sql,
symfony
mb_ucfirst
function mb_ucfirst($string, $encoding)
{
$strlen = mb_strlen($string, $encoding);
$firstChar = mb_substr($string, 0, 1, $encoding);
$then = mb_substr($string, 1, $strlen - 1, $encoding);
return mb_strtoupper($firstChar, $encoding) . $then;
}
Tuesday, September 25, 2012
Do Not Save Null Values in Embedded Form in Symfony
Think there is a Product object with many ProductPrice objects. The Product form contains some ProductPrice forms as embed forms. Prices are not mandatory fields. Now if you save the form, there will be null price rows in the ProductPrice table. Do the following in the ProductPrice model(!) class!
public function save(Doctrine_Connection $conn = null)
{
if($this->price > 0)
{
return parent::save();
}
else
{
$this->delete();
return null;
}
}
This will check the price (there is a price field in the ProductPrice table) is greater than 0 or not. If greater, it will save to the database. If not, it will delete the row in the table (if presents) and stop the saving process for this price object.
Doctrine: SQLSTATE[23000]: Integrity constraint violation duplicate entry
If you are using a table where some fields are I18N and ex. the title field is sluggable, you will realize that you cannot update(!) the object with the same title. See an example:
The page is multilingual (Hungarian and English). You create a product with TEFAL XY Hungarian and TEFAL XY English tilte (the same title used in each language). You can saved the form / object, it created successfully. Now you change the Hungarian title to TEFAL X. Save. Then change the English title to TEFAL X, too. You will get an error:
Doctrine: SQLSTATE[23000]: Integrity constraint violation duplicate entry
This is a bug in doctrine 1.2.x.
The page is multilingual (Hungarian and English). You create a product with TEFAL XY Hungarian and TEFAL XY English tilte (the same title used in each language). You can saved the form / object, it created successfully. Now you change the Hungarian title to TEFAL X. Save. Then change the English title to TEFAL X, too. You will get an error:
Doctrine: SQLSTATE[23000]: Integrity constraint violation duplicate entry
This is a bug in doctrine 1.2.x.
Solution
- Copy lib / vendor / symfony / lib / plugins / sfDoctrinePlugin / lib / vendor / doctrine / Doctrine / Template / Listener / Sluggable.php inside your own lib directory.
- In the getUniqueSlug method, change this line:
$whereString .= ' AND r.' . implode(' != ? AND r.', $table->getIdentifierColumnNames()) . ' != ?';
to this:
$whereString .= ' AND (r.' . implode(' != ? OR r.', $table->getIdentifierColumnNames()) . ' != ?)'; - Save. Clear cache. Be happy.
Monday, September 24, 2012
Hide Errors at Top of the Embed Form in Symfony
If you use embed forms, you will realise that the validatation errors appear twice, once near the input fields (in the embed form) and once at top of the embed form. To solve this....
I'm using the jroller plugin to generate auto admin:
plugins / sfAdminThemejRoller / data / generator / sfDoctrineModule / jroller / template / templates / _form_field.php
Use this (my solution):
[?php if ($form[$name]->hasError() && get_class($form[$name]) != 'sfFormFieldSchema'): ?]
[?php echo $form[$name]->renderError() ?]
[?php endif; ?]
I'm using the jroller plugin to generate auto admin:
plugins / sfAdminThemejRoller / data / generator / sfDoctrineModule / jroller / template / templates / _form_field.php
Use this (my solution):
[?php if ($form[$name]->hasError() && get_class($form[$name]) != 'sfFormFieldSchema'): ?]
[?php echo $form[$name]->renderError() ?]
[?php endif; ?]
Subscribe to:
Posts (Atom)