Category: Php

  • How @section, @yield, @stop and @show works in Larvel Blade Templates

    In this post, I want to reference some of my findings related to how the @section, @yield, @stop and @show commands work in Laravel’s Blade template engine as the official documentation regarding these subjects are pretty much non-existent. The @section command is used to define an area within your template, consider the following example: This is our master layout template named master.blade.php, it will reside in the app/views directory.

     <html> <title> @section('title') SiteName @show </title> <body> @yield('content') </body> </html> 

    Now what the @section is doing above is creating a placeholder area named title with a default value (SiteName). At end, we use @show, why? To tell it to display the content at that point. If we used @stop, it would not output the title, now take a look at the child template below for a View called home.blade.php (again, this resides in app/views directory of your Laravel installation):

     @extends('master') @section('title') Home | @parent @stop @section('content') A test sentence. @stop 

    The only thing its doing is defining content for this particular page / view. But the first thing it does is it tell it to extend the master template, so this child template extends our master template. It calls our section again and modifies it by appending Home | to the original title defined in our master template, so when its parsed as html it becomes Home | SiteName, neat huh? We used the @parent command to retrieve the original title defined by the parent / master template file. At the end we also use @stop command to tell it not to output anything right now, since it will be taken care of by the master template we created earlier. Because the Blade Template Engine does inheriting. One last thing I want to mention is that in the master template file above I used the following: @yield('content') This basically does the same thing as @section(‘content’) and is used if we simply don’t want the inherit (cascading) functionality. @yield is used when you simply want to overwrite the content instead of appending more content to the original.

    I hope those who come across this post, find it helpful.. I made this post in quite a hurry for reference purpose as I was just beginning to get into the Laravel Web Framework. If some thing feels confusing or unclear or if something could be improved then please do mention by commenting. Cheers!

    Share
  • SHARY – Free CS Cart Social Media Sharing Addon

    SHARY - Social Media Sharing Addon for CS CART I have recently gotten my hands dirty with CS Cart, which is a eCommerce shopping cart system similar to Magento and OpenCart. CS Cart is far less popular than the other shopping cart systems so finding decent, working and free addon for cs-cart is very less likely. I can tell you that CS Cart is fairly complex to get started, and it took me a while to get a decent grasp of how things work in their system; and I am still not up to full marks yet! but I’m getting there 🙂 I created my first add-on for cs-cart so wanted to share this simple, yet useful add-on for people who are running the latest CS Cart version. Which at the time of writing this post is version 4.3.

    The purpose of this add-on is to allow users the ability to share their favorite products on social media services such as Facebook, Google+, Twitter, Email, etc, etc.. The add-on comes with a very simple setting panel in the admin area where you can choose to select the social media services which you prefer. All the configuration is pretty simple and straight-forward so i don’t think a deep description of each option is necessary; But still if you find something confusing or broken then let me know. (more…)

    Share
  • Apache 2.2.x won’t load php5apache2.dll solution

    Recently, I started upgrading all my applications to the latest versions or at least upto the version my hosting providers uses – i was using Apache 1.3.x HTTP Server, but I’ve finally upgraded to the latest version which is Apache 2.2.15 & PHP 5.3.2 as of writing this post. I think it’s a good idea to keep your Apache / PHP and MySQL up-to date with the latest release or at least up-to date to match your Web Hosting Provider. Anyways, while i was upgrading from Apache 1.3.4 to Apache 2.2.15 i ran into a problem – Apache 2 actually installed pretty smoothly without any complicated issues arising. After the Apache & PHP Installation I started to setup Apache to use PHP where the real problem begin, Apache couldn’t load the php5apache2.dll Module, it was saying that the module can’t be found (look at the below pic to see the error i was getting). Apache 2.2.x Can't Load php5apache2.dll Module Error I was using the PHP Installation Manual (install.txt) all this time that came included with the PHP zip file, i had the below values added as said in that install file: # For PHP 5 do something like this: LoadModule php5_module "c:/php/php5apache2.dll" AddType application/x-httpd-php .php # configure the path to php.ini PHPIniDir "C:/php" I then double checked the PHP installation directory to make sure there is a file called php5apache2.dll and sure enough, it was there. While i was checking for the above file I also noticed that there is another file in that directory called php5apache2_2.dll. I tried giving that file a try and change the file name in httpd.conf from php5apache2.dll to php5apache2_2.dll, Which got it working! It was a really simple fix but very easy to overlook it. Hope this will save others (who come across this issue) some valuable time.

    Share
  • Upload Class For PHP

    class.upload.php – Free PHP Upload Class

    This PHP script uploads files and manipulates images very easily. The perfect script to generate thumbnails or create a photo gallery! It can convert, resize and work on uploaded images in many ways, add labels, watermarks and reflections and other image editing features. You can use it for files uploaded through an HTML form, a Flash uploader, or on local files. It uses the GD library. This script is released under the GPL Version 2.

    If your project is not GPL, commercial licenses are available.

    Look at the example below:

     $foo = new Upload($_FILES['form_field']); if ($foo->uploaded) { // save uploaded image with no changes $foo->Process('/home/user/files/'); if ($foo->processed) { echo 'original image copied'; } else { echo 'error : ' . $foo->error; } // save uploaded image with a new name $foo->file_new_name_body = 'foo'; $foo->Process('/home/user/files/'); if ($foo->processed) { echo 'image renamed "foo" copied'; } else { echo 'error : ' . $foo->error; } // save uploaded image with a new name, // resized to 100px wide $foo->file_new_name_body = 'image_resized'; $foo->image_resize = true; $foo->image_convert = gif; $foo->image_x = 100; $foo->image_ratio_y = true; $foo->Process('/home/user/files/'); if ($foo->processed) { echo 'image renamed, resized x=100 and converted to GIF'; $foo->Clean(); } else { echo 'error : ' . $foo->error; } } 

    (more…)

    Share