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...

Simple JavaScript Object and Class Examples

In JavaScript, most things are objects. An object is a collection of related data and/or functionality Namespace: Everything you create in JavaScript is by default global. In JavaScript namespace is Global object . How to create a namespace in JavaScript? Create one global object, and all variables, methods, and functions become properties of that object. Example:  // global namespace var MYAPP = MYAPP || {}; Explaination: Here we first checked whether MYAPP is already defined.If yes, then use the existing MYAPP global object, otherwise create an empty object called MYAPP How to create sub namespaces? // sub namespace MYAPP.event = {}; Class JavaScript is a prototype-based language and contains no class statement.JavaScript classes create simple objects and deal with inheritance. Example: var Person = function () {}; Explaination: Here we define a new class called Person with an empty constructor. Use the class keyword class Calculation {}; A class expr...

How to Add Next Previous links to The Event Calendar

Add Next/Previous links to The Event Calendar Wordpress Plugin Add code to your child theme’s functions.php file /**  * Allows visitors to page forward/backwards in any direction within month view */ if ( class_exists( 'Tribe__Events__Main' ) ) { class ContinualMonthViewPagination {     public function __construct() {         add_filter( 'tribe_events_the_next_month_link', array( $this, 'next_month' ) );         add_filter( 'tribe_events_the_previous_month_link', array( $this, 'previous_month' ) );     }     public function next_month() {         $url = tribe_get_next_month_link();         $text = tribe_get_next_month_text();         $date = Tribe__Events__Main::instance()->nextMonth( tribe_get_month_view_date() );         return '<a data-month="' . $date . '" href="' . $url . '" rel="next"...