Posts

Showing posts with the label PHP

PHP Topics | Latest Features | Lesser known Facts | Important for Entrance Exams

PHP Topics | Latest Features | Lesser known Facts | Important for Entrance Exams In this post, I am going to add my other personal projects that I have worked on in various technologies Reflection in PHP5 $class = new \ReflectionClass(MyClass’); $method = new \ReflectionMethod('MyClass',’method’); $args = array(); $method->invoke($method->getDeclaringClass()->newInstanceArgs($args)); Traits in PHP A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. It is an addition to traditional inheritance and enables horizontal composition of behavior; that is, the application of class members without requiring inheritance. Avoids the problems of Multiple inheritance. Is a parent constructor called implicitly in PHP? When a constructor is defined for a class in PHP, the parent construct...

Eloquent ORM | Laravel | Basics

Eloquent ORM Eloquent ORM: ORM stands for Ovject Relation Mapping. It converts an object to a database table row. To query the database, Eloquent has a lot of methods For example, we have a school database and inside the school database, we have a table of seventh standard The object contains the following properties. Each of the property is mapped to the column of the database If your model class is User, you should use User::all() to return all the tuples iof the database The where clause: Flight::where('active',1)->orderBy('name')->take(10)->get(); To get the first row of the row result set given by the where clause:- $flight = Flight::where('number','1000')->first(); $flight->number = '1000'; $flight->refresh(); echo $flight->number; foreach($flights as $flight) { echo $flight->name; } Flight::chunk(200, function(Collection $flights) { for...

Laravel | PHP | Basics | Part 2

Image
Learning Laravel through Screenshots Caching Laravel by default supports multiple cache stores like memcached , redis ,etc. To install redis as a cache store, you should use composer install predis/predis predis stands for PHP redis The default port number is 6379 Every Cache store requires a prefix which is stored in the ENV file or in the config/cache.php Following are the cache stores supported by laravel Blade Templates Blade is a templating engine for views in laravel. All the files which are of type blade.php are having the extension .blade.php They are stored in the resources/views directory YOu can create suub-folders in the reosurces/views directory like layouts for all the common UI components lke header , footer, sidebar , navbar, menubar, serach bar, etc. To include the parenet ...

Laravel | PHP | Basics | Part 1

Image
Laravel | PHP | Basics In this post, we will see the basics of laravel Laravel is a frame work on top of PHP (PHP Hypertext Preprocessor) for web artisans. When you download and install composer which is the dependency manager for PHP, you need to run the command composer install Getting started How to create a project in laravel: composer create-project laravel/laravel example-app OR composer global require laravel/installer laravel new example-app The config folder The entry point is in the config folder. In the config/database.php file, the "connection" key contains all the database drivers configuration available or provided by the laravel framework. The supported datavase drivers are sqlite mysql pgsql sqlsrv redis "mysql" => [ "driver" => "mysql", ...

PHP (PHP Hypertext Preprocessor)

PHP(PHP Hypertext Preprocessor) This article assumes you have basic to intermediate knowledge of PHP File handling functions:- fopen => $hf = fopen($html_file,"w"); fwrite => fwrite($hf, $htmlcontent); fclose => fclose($hf); unlink => unlink($html_file_path); filesize => filesize($file_path); chmod => chmod($file_path, 0777); Arrays To create an empty array, use the array function $empty_array = array(); To create an array of a single element, pass the name of the variable prefixed by the $ symbol as an argument to the array function $params = array($id); JSON To create an array of multiple elements, just pass the multiple variables arguments to the array function PHP supports two functions for dealing with JSON data To encode a variable either primitive or object, we use json_encode($obj) functio...