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

A Guide to UTF-8 for PHP and MySQL

Data Encoding: A Guide to UTF-8 for PHP and MySQL As a MySQL or PHP developer, once you step beyond the comfortable confines of English-only character sets, you quickly find yourself entangled in the wonderfully wacky world of UTF-8. On a previous job, we began running into data encoding issues when displaying bios of artists from all over the world. It soon became apparent that there were problems with the stored data, as sometimes the data was correctly encoded and sometimes it was not. This led programmers to implement a hodge-podge of patches, sometimes with JavaScript, sometimes with HTML charset meta tags, sometimes with PHP, and soon. Soon, we ended up with a list of 600,000 artist bios with double- or triple encoded information, with data being stored in different ways depending on who programmed the feature or implemented the patch. A classical technical rat’s nest.Indeed, navigating through UTF-8 related data encoding issues can be a frustrating and hair-pul...

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]');

Integrating Kafka with Node.js

Integrating Kafka with Node.js Apache Kafka is a popular open-source distributed event streaming platform that uses publish & subscribe mechanism to stream the records(data). Kafka Terminologies Distributed system: Distributed system is a computing environment where various software components located on different machines (over multiple locations). All components coordinate together to get stuff done as one unit.   Kafka Broker: Brokers are cluster of multiple servers. Message of each topic are split among the various brokers. Brokers handle all requests from clients to write and read events. A Kafka cluster is simply a collection of one or more Kafka brokers. Topics: A topic is a stream of "related" messages. Its unique throughout application. Kafka producers write messages to topics. Producer: Producer publishes data on the topics. A producer sends a message to a broker and the broker receives and stores messages. Consumers: Consumers read data from topics. A consu...