1596793342
The benefit of using any web application framework is that you don’t have to worry about the common tasks like input handling, form validation and the like, as the framework already provides wrappers for those features. Thus, it allows you to concentrate on the business logic of the application rather than reinventing the wheel over and over again.
Today, we’re going to explore an important library in the CodeIgniter framework—the pagination library.
CodeIgniter provides a very simple, but flexible pagination library that is simple to theme, works with the model, and capable of supporting multiple paginators on a single page.
Let me highlight the topics that we’re going to cover in the course of this article:
Below are the simple steps to create pagination in Codeigniter and MySQL.
Step 1 : Create Table In MySQL.
CREATE TABLE test.user ( id INT ( 6 ) UNSIGNED AUTO_INCREMENT PRIMARY KEY , name VARCHAR ( 30 ) NOT NULL , email VARCHAR ( 50 ), mobno bigint ( 10 ) ).
Step 2 : Insert Some Data Into Table.
INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user
( id
, name
, email
, mobno
) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );
Step 3 : Update application/config/database.php.
$db**[** ‘default’] = array**(** ‘dsn’ => ‘’ , ‘hostname’ => ‘localhost’ , ‘username’ => ‘root’ , ‘password’ => ‘’ , ‘database’ => ‘dbname’ , ‘dbdriver’ => ‘mysqli’ , ‘dbprefix’ => ‘’ , ‘pconnect’ => FALSE , ‘db_debug’ => ( ENVIRONMENT !== ‘production’) , ‘cache_on’ => FALSE , ‘cachedir’ => ‘’ , ‘char_set’ => ‘utf8’ , ‘dbcollat’ => ‘utf8_general_ci’ , ‘swap_pre’ => ‘’ , ‘encrypt’ => FALSE , ‘compress’ => FALSE , ‘stricton’ => FALSE , ‘failover’ => array**()** , ‘save_queries’ => TRUE**)** ;
Step 3 : Create a new model User_Model in application/models.
< ?php class User_Model extends CI_Model**{** private $table = ‘user’ ; public function getCount**()** { return $this -> db -> count_all**(** $this -> table**)** ; } public function getUsers**($limit** , $start)** { $this -> db -> limit**($limit** , $start)** ; $query = $this -> db -> get**(** $this -> table**)** ; return $query -> result**()** ; }} ?>
#codeigniter #mysql
1677668905
Mocking library for TypeScript inspired by http://mockito.org/
mock
) (also abstract classes) #examplespy
) #examplewhen
) via:verify
)reset
, resetCalls
) #example, #examplecapture
) #example'Expected "convertNumberToString(strictEqual(3))" to be called 2 time(s). But has been called 1 time(s).'
)npm install ts-mockito --save-dev
// Creating mock
let mockedFoo:Foo = mock(Foo);
// Getting instance from mock
let foo:Foo = instance(mockedFoo);
// Using instance in source code
foo.getBar(3);
foo.getBar(5);
// Explicit, readable verification
verify(mockedFoo.getBar(3)).called();
verify(mockedFoo.getBar(anything())).called();
// Creating mock
let mockedFoo:Foo = mock(Foo);
// stub method before execution
when(mockedFoo.getBar(3)).thenReturn('three');
// Getting instance
let foo:Foo = instance(mockedFoo);
// prints three
console.log(foo.getBar(3));
// prints null, because "getBar(999)" was not stubbed
console.log(foo.getBar(999));
// Creating mock
let mockedFoo:Foo = mock(Foo);
// stub getter before execution
when(mockedFoo.sampleGetter).thenReturn('three');
// Getting instance
let foo:Foo = instance(mockedFoo);
// prints three
console.log(foo.sampleGetter);
Syntax is the same as with getter values.
Please note, that stubbing properties that don't have getters only works if Proxy object is available (ES6).
// Creating mock
let mockedFoo:Foo = mock(Foo);
// Getting instance
let foo:Foo = instance(mockedFoo);
// Some calls
foo.getBar(1);
foo.getBar(2);
foo.getBar(2);
foo.getBar(3);
// Call count verification
verify(mockedFoo.getBar(1)).once(); // was called with arg === 1 only once
verify(mockedFoo.getBar(2)).twice(); // was called with arg === 2 exactly two times
verify(mockedFoo.getBar(between(2, 3))).thrice(); // was called with arg between 2-3 exactly three times
verify(mockedFoo.getBar(anyNumber()).times(4); // was called with any number arg exactly four times
verify(mockedFoo.getBar(2)).atLeast(2); // was called with arg === 2 min two times
verify(mockedFoo.getBar(anything())).atMost(4); // was called with any argument max four times
verify(mockedFoo.getBar(4)).never(); // was never called with arg === 4
// Creating mock
let mockedFoo:Foo = mock(Foo);
let mockedBar:Bar = mock(Bar);
// Getting instance
let foo:Foo = instance(mockedFoo);
let bar:Bar = instance(mockedBar);
// Some calls
foo.getBar(1);
bar.getFoo(2);
// Call order verification
verify(mockedFoo.getBar(1)).calledBefore(mockedBar.getFoo(2)); // foo.getBar(1) has been called before bar.getFoo(2)
verify(mockedBar.getFoo(2)).calledAfter(mockedFoo.getBar(1)); // bar.getFoo(2) has been called before foo.getBar(1)
verify(mockedFoo.getBar(1)).calledBefore(mockedBar.getFoo(999999)); // throws error (mockedBar.getFoo(999999) has never been called)
let mockedFoo:Foo = mock(Foo);
when(mockedFoo.getBar(10)).thenThrow(new Error('fatal error'));
let foo:Foo = instance(mockedFoo);
try {
foo.getBar(10);
} catch (error:Error) {
console.log(error.message); // 'fatal error'
}
You can also stub method with your own implementation
let mockedFoo:Foo = mock(Foo);
let foo:Foo = instance(mockedFoo);
when(mockedFoo.sumTwoNumbers(anyNumber(), anyNumber())).thenCall((arg1:number, arg2:number) => {
return arg1 * arg2;
});
// prints '50' because we've changed sum method implementation to multiply!
console.log(foo.sumTwoNumbers(5, 10));
You can also stub method to resolve / reject promise
let mockedFoo:Foo = mock(Foo);
when(mockedFoo.fetchData("a")).thenResolve({id: "a", value: "Hello world"});
when(mockedFoo.fetchData("b")).thenReject(new Error("b does not exist"));
You can reset just mock call counter
// Creating mock
let mockedFoo:Foo = mock(Foo);
// Getting instance
let foo:Foo = instance(mockedFoo);
// Some calls
foo.getBar(1);
foo.getBar(1);
verify(mockedFoo.getBar(1)).twice(); // getBar with arg "1" has been called twice
// Reset mock
resetCalls(mockedFoo);
// Call count verification
verify(mockedFoo.getBar(1)).never(); // has never been called after reset
You can also reset calls of multiple mocks at once resetCalls(firstMock, secondMock, thirdMock)
Or reset mock call counter with all stubs
// Creating mock
let mockedFoo:Foo = mock(Foo);
when(mockedFoo.getBar(1)).thenReturn("one").
// Getting instance
let foo:Foo = instance(mockedFoo);
// Some calls
console.log(foo.getBar(1)); // "one" - as defined in stub
console.log(foo.getBar(1)); // "one" - as defined in stub
verify(mockedFoo.getBar(1)).twice(); // getBar with arg "1" has been called twice
// Reset mock
reset(mockedFoo);
// Call count verification
verify(mockedFoo.getBar(1)).never(); // has never been called after reset
console.log(foo.getBar(1)); // null - previously added stub has been removed
You can also reset multiple mocks at once reset(firstMock, secondMock, thirdMock)
let mockedFoo:Foo = mock(Foo);
let foo:Foo = instance(mockedFoo);
// Call method
foo.sumTwoNumbers(1, 2);
// Check first arg captor values
const [firstArg, secondArg] = capture(mockedFoo.sumTwoNumbers).last();
console.log(firstArg); // prints 1
console.log(secondArg); // prints 2
You can also get other calls using first()
, second()
, byCallIndex(3)
and more...
You can set multiple returning values for same matching values
const mockedFoo:Foo = mock(Foo);
when(mockedFoo.getBar(anyNumber())).thenReturn('one').thenReturn('two').thenReturn('three');
const foo:Foo = instance(mockedFoo);
console.log(foo.getBar(1)); // one
console.log(foo.getBar(1)); // two
console.log(foo.getBar(1)); // three
console.log(foo.getBar(1)); // three - last defined behavior will be repeated infinitely
Another example with specific values
let mockedFoo:Foo = mock(Foo);
when(mockedFoo.getBar(1)).thenReturn('one').thenReturn('another one');
when(mockedFoo.getBar(2)).thenReturn('two');
let foo:Foo = instance(mockedFoo);
console.log(foo.getBar(1)); // one
console.log(foo.getBar(2)); // two
console.log(foo.getBar(1)); // another one
console.log(foo.getBar(1)); // another one - this is last defined behavior for arg '1' so it will be repeated
console.log(foo.getBar(2)); // two
console.log(foo.getBar(2)); // two - this is last defined behavior for arg '2' so it will be repeated
Short notation:
const mockedFoo:Foo = mock(Foo);
// You can specify return values as multiple thenReturn args
when(mockedFoo.getBar(anyNumber())).thenReturn('one', 'two', 'three');
const foo:Foo = instance(mockedFoo);
console.log(foo.getBar(1)); // one
console.log(foo.getBar(1)); // two
console.log(foo.getBar(1)); // three
console.log(foo.getBar(1)); // three - last defined behavior will be repeated infinity
Possible errors:
const mockedFoo:Foo = mock(Foo);
// When multiple matchers, matches same result:
when(mockedFoo.getBar(anyNumber())).thenReturn('one');
when(mockedFoo.getBar(3)).thenReturn('one');
const foo:Foo = instance(mockedFoo);
foo.getBar(3); // MultipleMatchersMatchSameStubError will be thrown, two matchers match same method call
You can mock interfaces too, just instead of passing type to mock
function, set mock
function generic type Mocking interfaces requires Proxy
implementation
let mockedFoo:Foo = mock<FooInterface>(); // instead of mock(FooInterface)
const foo: SampleGeneric<FooInterface> = instance(mockedFoo);
You can mock abstract classes
const mockedFoo: SampleAbstractClass = mock(SampleAbstractClass);
const foo: SampleAbstractClass = instance(mockedFoo);
You can also mock generic classes, but note that generic type is just needed by mock type definition
const mockedFoo: SampleGeneric<SampleInterface> = mock(SampleGeneric);
const foo: SampleGeneric<SampleInterface> = instance(mockedFoo);
You can partially mock an existing instance:
const foo: Foo = new Foo();
const spiedFoo = spy(foo);
when(spiedFoo.getBar(3)).thenReturn('one');
console.log(foo.getBar(3)); // 'one'
console.log(foo.getBaz()); // call to a real method
You can spy on plain objects too:
const foo = { bar: () => 42 };
const spiedFoo = spy(foo);
foo.bar();
console.log(capture(spiedFoo.bar).last()); // [42]
Author: NagRock
Source Code: https://github.com/NagRock/ts-mockito
License: MIT license
1595905879
HTML to Markdown
MySQL is the all-time number one open source database in the world, and a staple in RDBMS space. DigitalOcean is quickly building its reputation as the developers cloud by providing an affordable, flexible and easy to use cloud platform for developers to work with. MySQL on DigitalOcean is a natural fit, but what’s the best way to deploy your cloud database? In this post, we are going to compare the top two providers, DigitalOcean Managed Databases for MySQL vs. ScaleGrid MySQL hosting on DigitalOcean.
At a glance – TLDR
ScaleGrid Blog - At a glance overview - 1st pointCompare Throughput
ScaleGrid averages almost 40% higher throughput over DigitalOcean for MySQL, with up to 46% higher throughput in write-intensive workloads. Read now
ScaleGrid Blog - At a glance overview - 2nd pointCompare Latency
On average, ScaleGrid achieves almost 30% lower latency over DigitalOcean for the same deployment configurations. Read now
ScaleGrid Blog - At a glance overview - 3rd pointCompare Pricing
ScaleGrid provides 30% more storage on average vs. DigitalOcean for MySQL at the same affordable price. Read now
MySQL DigitalOcean Performance Benchmark
In this benchmark, we compare equivalent plan sizes between ScaleGrid MySQL on DigitalOcean and DigitalOcean Managed Databases for MySQL. We are going to use a common, popular plan size using the below configurations for this performance benchmark:
Comparison Overview
ScaleGridDigitalOceanInstance TypeMedium: 4 vCPUsMedium: 4 vCPUsMySQL Version8.0.208.0.20RAM8GB8GBSSD140GB115GBDeployment TypeStandaloneStandaloneRegionSF03SF03SupportIncludedBusiness-level support included with account sizes over $500/monthMonthly Price$120$120
As you can see above, ScaleGrid and DigitalOcean offer the same plan configurations across this plan size, apart from SSD where ScaleGrid provides over 20% more storage for the same price.
To ensure the most accurate results in our performance tests, we run the benchmark four times for each comparison to find the average performance across throughput and latency over read-intensive workloads, balanced workloads, and write-intensive workloads.
Throughput
In this benchmark, we measure MySQL throughput in terms of queries per second (QPS) to measure our query efficiency. To quickly summarize the results, we display read-intensive, write-intensive and balanced workload averages below for 150 threads for ScaleGrid vs. DigitalOcean MySQL:
ScaleGrid MySQL vs DigitalOcean Managed Databases - Throughput Performance Graph
For the common 150 thread comparison, ScaleGrid averages almost 40% higher throughput over DigitalOcean for MySQL, with up to 46% higher throughput in write-intensive workloads.
#cloud #database #developer #digital ocean #mysql #performance #scalegrid #95th percentile latency #balanced workloads #developers cloud #digitalocean droplet #digitalocean managed databases #digitalocean performance #digitalocean pricing #higher throughput #latency benchmark #lower latency #mysql benchmark setup #mysql client threads #mysql configuration #mysql digitalocean #mysql latency #mysql on digitalocean #mysql throughput #performance benchmark #queries per second #read-intensive #scalegrid mysql #scalegrid vs. digitalocean #throughput benchmark #write-intensive
1622006340
In this post I will show you pagination example in laravel, as we all know pagination is very common feature in all websites, if we want to display specific number of details or images then we can use pagination.
aravel provide paginate method and it will automatically takes care of setting the proper limit and offset based on the current page being viewed by the user.here i will show you how to use pagination in laravel, So I have try paginate method in laravel.
#pagination example in laravel #laravel #pagination #paginate method #how to use pagination in laravel #pagination in laravel
1596183830
Want to create unique, scalable web and app solutions?
At HourlyDeveloper.io, Expert CodeIgniter developer works particularly for you and your project.
You can Hire CodeIgniter Developer with an extensive variety of skill sets together with PHP, MySQL, PHP frameworks such as Laravel, CakePHP, and Zend, CMS, and e-commerce platforms such as WordPress, Drupal, Magento, WooCommerce, Shopify.
Consult with our experts: https://bit.ly/3hUdppScodeIgniter development services
#hire codeigniter developer #codeigniter developer #codeigniter development #codeigniter development company #codeigniter development services #codeigniter
1617355159
One of the fastest, lightest, reliable, and completely capable frameworks for a business web app development is the Codeigniter framework from PHP. CodeIgniter provides out-of-the-box libraries to perform operations like Sending Emails, Uploading Files, Managing Sessions, etc.
Want to build an excellent web application for your business?
Then WebClues Infotech is the right place where you could find highly skilled and expert CodeIgniter developers for hire. Share us your requirement, Conduct desired candidate interviews, and finally choose the one best suitably, it is that easy with WebClues Infotech.
So what are you waiting for? Get going on the path to business growth with WebClues Infotech
For more inquiry click here: https://www.webcluesinfotech.com/contact-us/
Hire CodeIgniter Developer: https://www.webcluesinfotech.com/hire-codeigniter-developer/
Email: sales@webcluesinfotech.com
#hire codeigniter developers #hire codeigniter development expert #hire codeigniter developers #hire codeigniter developers or programmers #hire an offshore codeigniter development team #codeigniter programmer