Skip to main content

Cakephp testimonials

CakePHP testimonials

Components and Plugins are still separate entities in Cake 2.0. According to the manual components are "are packages of logic that are shared between controllers", whereas plugins are "a combination of controllers, models, and views". Compoments extend the base Component class, while Plugins have their own AppModel and AppController.
Think of a plugin as a separate Cake application sharing the same core libraries with your main application.
How to use vendor in cakephp
App::import('Vendor', 'Custom/getdata');
$obj = new GetData();

Lib

Contains 1st party libraries that do not come from 3rd parties or external vendors. This allows you to separate your organization’s internal libraries from vendor libraries.

Vendor

Any third-party classes or libraries should be placed here. Doing so makes them easy to access using the App::import(‘vendor’, ‘name’) function. Keen observers will note that this seems redundant, as there is also a vendors folder at the top level of our directory structure. We’ll get into the differences between the two when we discuss managing multiple applications and more complex system setups.
To clarify further, Libis recommended for libraries that you write yourself. This may just be a few classes or entire libraries. Vendor is recommended for libraries or scripts that you may download from github for instance. Plugin is strictly for cakephp framework plugins.

Regarding Lib vs Vendor for you own scripts or 3rd party scripts there is no difference that I am aware of. I have put my own scripts in both as well as 3rd party scripts in both locations and it hasn't made any difference. It's just a recommended way to organize your files.
You can load your scripts from Lib or Vendor using App::import() which is the same as require_once(). 
To load framework files or your own scripts that follow cakephp conventions, you would use App::uses().
Examples: How to use helper function inside controllers
    App::uses('CommonHelper', 'View/Helper');
    $yourHelper = new CommonHelper(new View());
    pr($yourHelper->getBrowser()); exit;
                OR
    App::import('View/Helper', 'CommonHelper');
    $yourHelper = new CommonHelper(new View());
    pr($yourHelper->getBrowser()); exit;
Examples: How to use element inside controllers
    $view = new View($this, false);
    $content = $view->element('header', $params);
                OR
    $this->render('/Elements/header');
                OR
    $this->render(null, 'ajax', VIEW . /elements/header.ctp);
Examples : Extend view inside another view.
    // app/View/Common/index.ctp
    <h1><?php echo $this->fetch('title'); ?></h1>
    <?php echo $this->fetch('top-content');
        echo $this->fetch('panels'); ?>
    <?php
    // app/View/Locations/view.ctp
    $this->extend('/Common/index');
    $this->assign('title', 'Some Title');
    $this->start('top-content');
    ?>
    <div id="map_canvas">
      <p>Hello, world!</p>
    </div>
    <?php $this->end();
    $this->append('panels');
    echo '<div class="box-title">
                <i class="icon-list"></i>
                Publishing
            </div>'.
        $this->Form->button(__d('croogo', 'Save')),
        $this->Html->link(__d('croogo', 'Cancel'),
            array('action' => 'index'),
            array('button' => 'danger')
        );
    $this->end();?>
Examples: How to create breadcrumb
    Using the HTML Helper:
    echo $this->Html->getCrumbs(' > ','Home');
    Note: $this->Html->getCrumbs(): It gets all the addCrumbs being added. The parameters are the “separator” ( >) which can be replaced by anything of our wish.
    $this->Html->addCrumb('Users', '/users');
    $this->Html->addCrumb('Add User', '/users/add', array('class' => 'breadcrumblast'));
    Note: $this->Html->addCrumb() : Add breadcrumb element
    Output:
    Home > Users > Add User

Comments

Popular posts from this blog

Generate XML file in Cakephp

Steps to Generate XML file using CakePHP: Step-1 Enable to parse xml extension in config route.php file.     Router::parseExtensions('xml'); Step-2 Add Request Handler Component to the Controller    var $components = array(‘RequestHandler’); Step-3 Add controller Action For XML Generation in Post Controller     function generateXMLFile()     {         if ($this->RequestHandler->isXml()) { // check request type             $this->layout = 'empty'; // create an empty layout in app/views/layouts/empty.ctp              }        }  Add header code in empty layout <?php header('Content-type: text/xml');?> <?php echo $this->Xml->header(); ?> <?php echo $content_for_layout; ?> Step-4 Set up View To generate XML Create xml folder inside Posts vi...

How To Create Shortcodes In WordPress

We can create own shortcode by using its predified hooks add_shortcode( 'hello-world', 'techsudhir_hello_world_shortcode' ); 1. Write the Shortcode Function Write a function with a unique name, which will execute the code you’d like the shortcode to trigger: function techsudhir_hello_world_shortcode() {    return 'Hello world!'; } Example: [hello-world] If we were to use this function normally, it would return Hello world! as a string 2. Shortcode function with parameters function techsudhir_hello_world_shortcode( $atts ) {    $a = shortcode_atts( array(       'name' => 'world'    ), $atts );    return 'Hello ' . $a['name'] . !'; } Example: [hello-world name="Sudhir"] You can also call shortcode function in PHP using do_shortcode function Example: do_shortcode('[hello-world]');

How to replace plain URLs with links

Here we will explain how to replace Urls with links from string Using PHP $string ='Rajiv Uttamchandani is an astrophysicist, human rights activist, and entrepreneur. Academy, a nonprofit organization dedicated to providing a robust technology-centered education program for refugee and displaced youth around the world.  CNN Interview - https://www.youtube.com/watch?v=EtTwGke6Jtg   CNN Interview - https://www.youtube.com/watch?v=g7pRTAppsCc&feature=youtu.be'; $string = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.%-=#]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $string); Using Javascript <script> function linkify(inputText) {     var replacedText, replacePattern1, replacePattern2, replacePattern3;     //URLs starting with http://, https://, or ftp://     replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;     replacedText = inputT...