Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Discussion on helpers in cakephp 2.x with example

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 433
    Comment on it

    Hi Reader's,
    Welcome to FindNerd,today we are going to discuss helpers in cakephp 2.x.

    If we are making any web application in CakePHP then sometimes we have to use helper for extending the functionality of view. Because helper is used for making html options easier and flexible for the view.

    So, In other words we can say that helpers are the component-like classes which is used to the presentation layer of our CakePHP web application. Helper contains presentational logic that is used for sharing between many views and layouts.

    Suppose we want add style.css in our web application then our code will like below:

    HtmlHelper::css(mixed $path, array $options = array())

    we can see below code how it will call

    <?php
     echo $this->Html->css('style');
    ?>

    This code will similar to like below code:

    <link rel="stylesheet" type="text/css" href="/css/forms.css" />

    We can use link helper to generate hyper link in below example

    <?php 
        class PostsController extends AppController {
        //Here include Helper in your controller
        public $helpers = array('Link');
        }
    // Below code we can see how to use this helper in view file
    <?php echo $this->Link->makeEdit('Change this Post', '/posts/edit/5'); ?>
    
    ?>

    If we want to add any script file then we will use HtmlHelper::script(mixed $url, mixed $options) to include a script file in cakephp.

    It will call like below code:

    <?php  echo $this->Html->script('custom'); ?>

    It will look similar to below code:

    <script type="text/javascript" href="/js/custom.js"></script>

    I hope this blog will help you to use helpers in your CakePHP web application.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: