Thursday, December 22, 2016

joomla 301 redirection from with index.php to without URLs

This can be done using .htaccess file. Open it and add the following code

RewriteEngine On

########## Begin - 301 Redirect

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.yourdomain.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^(([^/]+/)*)index\.php$ http%2://www.yourdomain.com/$1 [R=301,L]

#RedirectMatch 301 ^/index.php/(.*)$ http://www.yourdomain.com/$1

RewriteCond %{REQUEST_URI} ^/index\.php/
RewriteRule ^index.php/(.*) /$1 [R,L]

RewriteCond %{HTTP_HOST} !^(www\.yourdomain\.com)?$
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
########## End - 301 Redirect


*****************************************************************
 
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ http://www.yourdomain.com [R=301,L] 
 
RewriteCond %{REQUEST_URI} ^/index\.php/
RewriteRule ^index.php/(.*) /$1 [R,L] 

Tuesday, July 12, 2016

Yii - Multiple Insert Command

New method CDbCommandBuilder::createMultipleInsertCommand()

There's now CDbCommandBuilder::createMultipleInsertCommand() to support insertion of multiple records in a single query:

$builder=Yii::app()->db->schema->commandBuilder;

$command=$builder->createMultipleInsertCommand('tbl_post', array(
  array('title' => 'record 1', 'text' => 'text1'),
  array('title' => 'record 2', 'text' => 'text2'),
));

$command->execute();

Example:

 Use Like this....

 $alertStatus[] = array(
                        'db_field_name1' => $value1,
                        'db_field_name1' => $value2,
                        'created_on' => new CDbExpression('NOW()'),
                        'modified_on' => new CDbExpression('NOW()')
                    );

 $connection = Yii::app()->db->getSchema()->getCommandBuilder();
 $command   = $connection->createMultipleInsertCommand('table_name', $alertStatus);
$command->execute();

Friday, July 08, 2016

Yii - Give attribute values to each option in dropDownList

How can we give some attribute values to each option. For Example I need to build a dropdownlist looks like below.

<select>
    <option value="a" myAttribute="xyz">Calendar</option>
    <option value="n" myAttribute="PQR">Shopping Cart</option>
    <option value="c" myAttribute="ABC">CD</option>
    <option value="d" myAttribute="HMN">Email</option>  
</select>

values and myAttributes's value are coming from table. How can I implement this by altering the following?


Yeah have a solution to implement..Here the below solution.

In View:

<?php
     echo $form->dropDownList($model,'media_ids',
               'data' => CHtml::listData(Media::model()->findAll(), 'id', 'name'),
                array(
                     'options' =>  CHtml::listData(Media::model()->findAll(), 'id', 'option_array')
                     )
     );
?>

In Model:

public function getOption_array() {
        return array('myAttribute' => $this->media_title);
    }


Cheers !!!

Friday, June 10, 2016

Check if array value is empty in an existing array

Here is my array ouput

 Array
(
    [1] => 1
    [2] => 2
    [3] => 
)

How do I know the [3] => is empty?

Solution:

$array = array('one', 'two', '');

if(count(array_filter($array)) == count($array)) {
    echo 'OK';
} else {
    echo 'ERROR';
}

 

Tuesday, April 26, 2016

PutObject into directory Amazon s3 / PHP

In Laravel.5 ,  You should be able to use the temp file contents in the API,
and specify the file name separately. 


// Get the UploadedFile object
$file = Request::file('uploadImageFile');

// You can store this but should validate it to avoid conflicts
$original_name = $file->getClientOriginalName();

// This would be used for the payload
$file_path = $file->getPathName();

// Example S3 API upload
$s3client->putObject([
    'Key' => $original_name, // This will overwrite any other files with same name
    'SourceFile' => $file_path,
    'Bucket' => 'bucket_name'
]);


// Example

$localImage = '/Users/jim/Photos/summer-vacation/DP00342654.jpg';
$s3->putObject(array(
    'Bucket'     => 'my-uniquely-named-bucket',
    'SourceFile' => $localImage,
    'Key'        => 'photos/summer/' . basename($localImage)
));

Tuesday, April 12, 2016

input array sum with jQuery

Example how sum all values of those fields

<input type="hidden" name="hidden[1]" class="sum" value="31">
<input type="hidden" name="hidden[2]" class="sum" value="21">
<input type="hidden" name="hidden[3]" class="sum" value="321">
<input type="hidden" name="hidden[4]" class="sum" value="-31">
<input type="hidden" name="hidden[5]" class="sum" value="31.12">
<input type="hidden" name="hidden[6]" class="sum" value="0">


If you have 'sum' as a class to define all the elements that must be calculated,
below code should work...


 <script>
 var total = 0;
 $('.sum').each(function () {
      total += parseFloat(this.value);
  });
</script>

Wednesday, March 30, 2016

Fixed - Document Expired when using back button of browser

Searched a bit and found this proposed "solution":

<?php session_cache_limiter('private_no_expire'); // must go before session start session_start(); ?>

For details, see http://php.net/manual/en/function.session-cache-limiter.php

Found here: https://support.mozilla.org/en-US/questions/922734?page=2

More possible solutions and info here: http://stackoverflow.com/questions/10795552/php-document-expired

Redirect url with dynamic server address in .htacess

To make it more dynamic lets use SERVER_NAME and REQUEST_URI instead of a static domain name. This is the way to redirect to HTTP non-www to HTTPS www htaccess.

RewriteEngine On

#we replace domain.com/$1 with %{SERVER_NAME}%{REQUEST_URI}.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) http://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

#here we dont use www as non www was already redirected to www.
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
 
 

Friday, March 18, 2016

Joomla default search module

Every web site has a search box because there is no point writing great content on your web site if no one can find it. Usually the search box is in the top right hand corner of your web site. If we put in the secret url ?tp=1 we can see that there is a position up here in the top right called position-0 and we're going to use that for our search box. 

In the administrator go to Extensions and Module Manager Now click on New and we can see a long list of all the modules that Joomla is shipped with. Here is one called Search Click on that to select it. We now need to give the module a title so that we can find it again. Search is as good as any. Place the module in the position that we just found which was Position-0. Click Save. Return to your web site remove that secret url and the search box is here. If we click inside the search box and do a search we can see all the results. 

Now currently you will notice that the search also gives you the option to search only in the following parts of your web site. Categories, Contacts, Articles Newsfeeds and Weblinks. We're only using Articles and Contacts on this web site so we can remove the ability to search inside of Categories, Newsfeeds and Weblinks. It will just tidy up the web site a little. 

Go to : Extensions > Module Manager > New > Search

Thursday, March 10, 2016

Joomla 3 - Get article intro Image by article Id


Here the following post is useful to get article images from the article id in joomla3.

$article_id = JFactory::getApplication()->input->get('id'); // get article id

$article = JTable::getInstance("content");
$article->load(JRequest::getInt("id")); // Get Article ID
$article_images = $article->get("images"); // Get image parameters
$pictures = json_decode($article_images); // Split the parameters apart

// Print the image
echo "<img src='" . $pictures->image_intro . "' alt='" . $pictures->image_intro_alt . "'>";

Good Luck!! Cheers :)

Wednesday, January 27, 2016

Add Foreign Key to existing table

To add a foreign key (grade_id) to an existing table (users), follow the following steps:

ALTER TABLE users ADD grade_id SMALLINT UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE users ADD CONSTRAINT fk_grade_id FOREIGN KEY (grade_id) REFERENCES grades(id);

Wednesday, January 06, 2016

Display a popup on loading first time only in the browser


Is to set a cookie which is basically a file that sits in your browser and contains some kind of data. On the first page load you would create a cookie. Then every page after that you check if your cookie is set. If it is set do not display the pop up. However if its not set set the cookie and display the pop-up.

Try HTML localStorage.

Methods :
  • localStorage.getItem('key');
  • localStorage.setItem('key','value');

<div id="popup">
    <div>
        <div id="popup-close">X</div>
            <h2>Content Goes Here</h2>
    </div>
</div>

$(document).ready(function() {
 
    if(localStorage.getItem('popState') != 'shown'){
        $("#popup").delay(2000).fadeIn();
        localStorage.setItem('popState','shown')
    }

    $('#popup-close').click(function(e) // You are clicking the close button
    {
        $('#popup').fadeOut(); // Now the pop up is hiden.
    });

    $('#popup').click(function(e) 
    {
        $('#popup').fadeOut(); 
    });
});
 

Working Demo

 Cheers :)