Codxplore.com

Latest news:

New android application Islamic Video has been released. its a free islamic video application for android smartphone. Download now!

Pagination in react by react-paginate

Pagination in react by react-paginate



react-paginate

A ReactJS component to render a pagination.

By installing this component and writing only a little bit of CSS you can obtain this:

Installation:

Install react-paginate with npm:

$ npm install react-paginate --save

To use this we need to import it
 

import ReactPaginate from 'react-paginate';

You will quickly understand how to make react-paginate work with a list of objects by below code.

< ReactPaginate
                 previousLabel={'previous'}
                 nextLabel={'next'}
                 breakLabel={'...'}
                 breakClassName={'break-me'}
                 pageCount={this.state.total_pages}
                 marginPagesDisplayed={2}
                 pageRangeDisplayed={5}
                 onPageChange={this.handlePageClick.bind(this)}
                 containerClassName={'pagination'}
                 subContainerClassName={'pages pagination'}
                 activeClassName={'active'}
                 pageClassName={'page-item'}
                 pageLinkClassName={'page-link'}
                 previousClassName={'page-link'}
                 nextClassName={'page-link'}
                 hrefBuilder={this.buildPaginateHref}
/ >

Read full documentation here https://www.npmjs.com/package/react-paginate


Views: 58

How to insert HTML in react js?

How to insert HTML in react js?



In react project sometimes need to show raw HTML content. React simply does not allow us to put raw HTML content.
In that case we need to use dangerouslySetInnerHTML dom element in order to resolve that issue. For example

render: function() {
    return (
        <div className="myClassName" dangerouslySetInnerHTML={{__html: this.state.cms_info.content}}>div>
    );
}

Please keep in mind that
dangerouslySetInnerHTML  can be dangerous if you do not know what is in the HTML string you are adding, sometimes malicious client side code can be injected via script tags.


Views: 73

Yii2 : Checkbox rules not working

Yii2 : Checkbox rules not working



If you want to show error message when checkbox is not checked, try this rule

 ['acordul_tc', 'required', 'on' => ['register'], 'requiredValue' => 1, 'message' => 'my test message']

This means that the attribute is required and must be equal to 1, else display error with your message.


Views: 1166

Temporarily disable foreign key constraint mysql

Temporarily disable foreign key constraint mysql



Try DISABLE KEYS before

SET FOREIGN_KEY_CHECKS=0;

make sure to

SET FOREIGN_KEY_CHECKS=1;

after.

[NOTE]

It's not a good idea to set a foreign key constraint to 0, because if you do, your database would not ensure it is not violating referential integrity. This could lead to inaccurate, misleading, or incomplete data.

You make a foreign key for a reason: because all the values in the child column shall be the same as a value in the parent column. If there are no foreign key constraints, a child row can have a value that is not in the parent row, which would lead to inaccurate data.

For instance, let's say you have a website for students to login and every student must register for an account as a user. You have one table for user ids, with user id as a primary key; and another table for student accounts, with student id as a column. Since every student must have a user id, it would make sense to make the student id from the student accounts table a foreign key that references the primary key user id in the user ids table. If there are no foreign key checks, a student could end up having a student id and no user id, which means a student can get an account without being a user, which is wrong.

Imagine if it happens to a large amount of data. That's why you need the foreign key check.

It's best to figure out what is causing the error. Most likely, you are trying to delete from a parent row without deleting from a child row. Try deleting from the child row before deleting from the parent row.


Views: 994

How to run foreach loop between 2 given dates ?



$begin = new DateTime( '2010-05-01' );
$end = new DateTime( '2010-05-10' );

$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);

foreach ( $period as $dt )
  echo $dt->format( "l Y-m-d H:i:s\n" );

This will output all days in the defined period between $start and $end. If you want to include the 10th, set $end to 11th. You can adjust format to your liking. See the PHP Manual for DatePeriod.


Views: 3464

Displaying the list of months using mktime for the year



Use this:

for ($m=1; $m<=12; $m++) {
     $month = date('F', mktime(0,0,0,$m, 1, date('Y')));
     echo $month. '
'
; }

Views: 3484

How to get the first and last days of a given month



You might want to look at the strtotime and date functions.

php

$query_date = '2010-02-04';

// First day of the month.
echo date('Y-m-01', strtotime($query_date));

// Last day of the month.
echo date('Y-m-t', strtotime($query_date));

Views: 3210

GLYPHICONS - bootstrap icon font hex value



We can find these by looking at Bootstrap's stylesheet, Bootstrap.css. Each {number} represents a hexadecimal value, so 2a is equal to 0x2a or &#x2a;.

As for the font, that can be downloaded from http://glyphicons.com.

<pre>

.glyphicon-asterisk:before {
  content: "2a";
}

.glyphicon-plus:before {
  content: "2b";
}

.glyphicon-euro:before {
  content: "20ac";
}

.glyphicon-minus:before {
  content: "2212";
}

.glyphicon-cloud:before {
  content: "2601";
}

.glyphicon-envelope:before {
  content: "2709";
}

.glyphicon-pencil:before {
  content: "270f";
}

.glyphicon-glass:before {
  content: "e001";
}

.glyphicon-music:before {
  content: "e002";
}

.glyphicon-search:before {
  content: "e003";
}

.glyphicon-heart:before {
  content: "e005";
}

.glyphicon-star:before {
  content: "e006";
}

.glyphicon-star-empty:before {
  content: "e007";
}

.glyphicon-user:before {
  content: "e008";
}

.glyphicon-film:before {
  content: "e009";
}

.glyphicon-th-large:before {
  content: "e010";
}

.glyphicon-th:before {
  content: "e011";
}

.glyphicon-th-list:before {
  content: "e012";
}

.glyphicon-ok:before {
  content: "e013";
}

.glyphicon-remove:before {
  content: "e014";
}

.glyphicon-zoom-in:before {
  content: "e015";
}

.glyphicon-zoom-out:before {
  content: "e016";
}

.glyphicon-off:before {
  content: "e017";
}

.glyphicon-signal:before {
  content: "e018";
}

.glyphicon-cog:before {
  content: "e019";
}

.glyphicon-trash:before {
  content: "e020";
}

.glyphicon-home:before {
  content: "e021";
}

.glyphicon-file:before {
  content: "e022";
}

.glyphicon-time:before {
  content: "e023";
}

.glyphicon-road:before {
  content: "e024";
}

.glyphicon-download-alt:before {
  content: "e025";
}

.glyphicon-download:before {
  content: "e026";
}

.glyphicon-upload:before {
  content: "e027";
}

.glyphicon-inbox:before {
  content: "e028";
}

.glyphicon-play-circle:before {
  content: "e029";
}

.glyphicon-repeat:before {
  content: "e030";
}

.glyphicon-refresh:before {
  content: "e031";
}

.glyphicon-list-alt:before {
  content: "e032";
}

.glyphicon-lock:before {
  content: "e033";
}

.glyphicon-flag:before {
  content: "e034";
}

.glyphicon-headphones:before {
  content: "e035";
}

.glyphicon-volume-off:before {
  content: "e036";
}

.glyphicon-volume-down:before {
  content: "e037";
}

.glyphicon-volume-up:before {
  content: "e038";
}

.glyphicon-qrcode:before {
  content: "e039";
}

.glyphicon-barcode:before {
  content: "e040";
}

.glyphicon-tag:before {
  content: "e041";
}

.glyphicon-tags:before {
  content: "e042";
}

.glyphicon-book:before {
  content: "e043";
}

.glyphicon-bookmark:before {
  content: "e044";
}

.glyphicon-print:before {
  content: "e045";
}

.glyphicon-camera:before {
  content: "e046";
}

.glyphicon-font:before {
  content: "e047";
}

.glyphicon-bold:before {
  content: "e048";
}

.glyphicon-italic:before {
  content: "e049";
}

.glyphicon-text-height:before {
  content: "e050";
}

.glyphicon-text-width:before {
  content: "e051";
}

.glyphicon-align-left:before {
  content: "e052";
}

.glyphicon-align-center:before {
  content: "e053";
}

.glyphicon-align-right:before {
  content: "e054";
}

.glyphicon-align-justify:before {
  content: "e055";
}

.glyphicon-list:before {
  content: "e056";
}

.glyphicon-indent-left:before {
  content: "e057";
}

.glyphicon-indent-right:before {
  content: "e058";
}

.glyphicon-facetime-video:before {
  content: "e059";
}

.glyphicon-picture:before {
  content: "e060";
}

.glyphicon-map-marker:before {
  content: "e062";
}

.glyphicon-adjust:before {
  content: "e063";
}

.glyphicon-tint:before {
  content: "e064";
}

.glyphicon-edit:before {
  content: "e065";
}

.glyphicon-share:before {
  content: "e066";
}

.glyphicon-check:before {
  content: "e067";
}

.glyphicon-move:before {
  content: "e068";
}

.glyphicon-step-backward:before {
  content: "e069";
}

.glyphicon-fast-backward:before {
  content: "e070";
}

.glyphicon-backward:before {
  content: "e071";
}

.glyphicon-play:before {
  content: "e072";
}

.glyphicon-pause:before {
  content: "e073";
}

.glyphicon-stop:before {
  content: "e074";
}

.glyphicon-forward:before {
  content: "e075";
}

.glyphicon-fast-forward:before {
  content: "e076";
}

.glyphicon-step-forward:before {
  content: "e077";
}


Views: 3457

How to Call action of other Controller in YII2



When we need to to call another controller function,we can simply use the below code

Yii::$app->runAction('publish/commit',[
                    'r' => 'ws'
]);

write it in Controller A index method and you can get the value of $r  in Controller Publish commit method.

 

 


Views: 3700

php export csv utf 8



If your generating a CSV with PHP you may have stumbled upon the same problem as me where any special character such as £ becomes ASCII in your CSV, this is because the encoding of your CSV is wrong and you will need to output your CSV in UTF8 to be able to use special ASCII characters in your document.

Using my example below you can encode UTF8 your CSV file, you will notice a header with “Content-Encoding: UTF-8” and also in the “Content-Type” header you will see an extra parameter “; charset=UTF-8”. You will also notice the weird echo “xEFxBBxBF” – this is the BOM for the UTF-8 encoding, if your not sure what this is don't worry, it will not display in your document.

Please Note! UTF-8 is not supported by Macintosh version of Excel, so you will see both the BOM and the encode characters instead of the correct character – there is no fix for this and you will have to provide a version of the CSV without special characters if you need to avoid it.

So here is my example code, this will generate a CSV file using PHP’s CSV functions and will add UTF-8 support:

 

header('Content-Encoding: UTF-8');
header("Content-type: text/csv; charset=UTF-8");
header("Content-Disposition: attachment; filename=processed_devices.csv");
header("Pragma: no-cache");
header("Expires: 0");
echo "xEFxBBxBF";
$fp = fopen('php://output', 'w');
$list = array(
        array('id', 'name', 'value'),
        array('1', 'brent', '12'),
        array('1', 'matt', '45'),
        array('1', 'gaz', '34'),
        array('1', 'tom', '76')
    );
foreach ($list as $fields) {
    fputcsv($fp, $fields);
}
fclose($fp);

 


Views: 3564

Yii2 Validate Only Create Action



 

Its called 'scenarios': http://www.yiiframework.com/doc-2.0/guide-structure-models.html#scenarios

in model:

public function rules()
{
    return [
        ['title', 'required', 'on' => 'create']
    ];
}

in controller:

public function actionCreate()
{
     $model = new Item();
     $model->scenario = 'create';
     ...
}

You'd better define scenario as a constant though.

 

source : http://stackoverflow.com/questions/29449019/yii2-validate-only-create-action


Views: 3741

Remove apostrophe in string



Have a look at

http://www.webmasterworld.com/forum88/7382.htm

I believe that it will work OK if you escape the ' character thus: '
You can easily create a Javascript function to replace each instance of ' by '.

str = str.replace(/'/g, "\'");


Views: 3718

Subscribe Us


Follow Us