Giter VIP home page Giter VIP logo

diggriola's Introduction

Diggriola
=========

Abstraction layer for Models between Nette & NotORM.

Complete tutorial in Slovak language can be found at http://wiki.nette.org/cs/cookbook/jednoduchy-model-s-notorm


Diggriola is simple layer for accesing (loading) Models in Nette Framework.
It is using excellent library NotORM by Jakub Vrána for database abstraction.
With usage of Nette's DI implementation, obtaining of Model instance
and table resultset is simple as:

final class FooPresenter extends BasePresenter {
    public function renderDefault() {
        $model = $this->getModel('application');
        $applications = $model->findByAuthorName('John Doe');
    }
}

Resultset can be iterated:

foreach ($applications as $app) {
    echo "$app[name]: ";
	foreach ($app->applications_tags() as $application_tag) { // M:N tags
		echo "{$application_tag->tag['name']}, ";
	}
	echo '<br>';
}

All Models must inherit from Diggriola\BaseModel and be in Model namespace!


Installation
------------

- put Diggriola folder to your LIBS_DIR
- register services in app/config.neon

    common:
      services:

        modelLoader:
          class: Diggriola\ModelLoader
          arguments: ['@dbConnection']

        dbConnection:
          factory: Diggriola\ModelLoader::dbConnect

- setup DB connection in app/config.neon

    development < common:

      database:
        driver: mysql
        host: localhost
        database: nette_notorm
        username: php
        password: php
        profiler: true

- write method for obtaining Models in BasePresenter

    abstract class BasePresenter extends \Nette\Application\UI\Presenter {
        protected function getModel($model) {
            return $this->context->modelLoader->getModel($model);
        }
    }

- create model representing DB table

    <?php
    namespace Model;

    class Application extends \Diggriola\BaseModel {

    }

- setup session in app/bootstrap.php

    $configurator->container->session->setExpiration('+ 90 days');
    $configurator->container->session->start();

Thats it! Now you can enjoy Diggriola Models


Model API
---------

- <NotORM_Result> Diggrila\BaseModel::findBy<Column>(<column value>)

  example: $applications = $applicationModel->findByName('Firefox');


- <NotORM_Result> Diggrila\BaseModel::findBy<Related table><Column>(<column value>)

  example: $applications = $applicationModel->findByAuthorName('John Doe');


- <NotORM_Result> Diggrila\BaseModel::findBy<Related table><Column>(<column value>, true)

  example: $applications = $applicationModel->findByTagName('php', true);


- <NotORM_Row> Diggrila\BaseModel::insert(<data array>)

  example: $applicationModel->insert(array(
             'name' => 'calc 3000',
             'author_id' => '5',
           ));


- Diggrila\BaseModel::update(<NotORM_Result>, <data array>)

  example: $applications = $applicationModel->findByAuthorName('John Doe');
           $affected = $applicationModel->update(applications, array('status'=>'unsupported'));


- Diggrila\BaseModel::delete(<NotORM_Result>)

  example: $applications = $applicationModel->findByAuthorName('John Doe');
           $affected = $applicationModel->delete(applications);


Feel free to introduce own API extensions by modifiing Diggriola\BaseModel in your applications :)


Requirements
------------

- PHP 5.3
- Nette Framework 2.0 beta or DEV for PHP 5.3
- NotORM (dev)


Feedback appreciated,
cheers, srigi :)

diggriola's People

Contributors

janvoracek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.