Giter Site home page Giter Site logo

slim-documentation's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slim-documentation's Issues

Incorrect instructions for slim/twig-view

According to http://docs-new.slimframework.com/features/templates/ ("Register the view service"), the code to use is:

// Create Slim app
$app = new \Slim\App();

// Register Twig View service
$app->register(new \Slim\Views\Twig('path/to/templates', [
    'cache' => 'path/to/cache'
]));

However that throws a fatal error Call to undefined method Slim\App::register().

From the readme at https://github.com/slimphp/Twig-View it seems the correct code is actually:

// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Twig View helper
$container->register(new \Slim\Views\Twig('path/to/templates', [
    'cache' => 'path/to/cache'
]));

.. which seems to at least get rid of the error.

Recommendation to install using `composer require`

I tried to find where the installation document was to make a PR but have failed.

My suggestion is to recommend that rather than manually creating composer.json then copying and pasting from the file, simply use composer require slim/slim to install and Composer will create the file for you.

A chapter on testing

Hey,

We should add a chapter on testing, so people can learn and improve their code.

Thanks

Injecting view

Hi,

I think it is good to show how to inject a Twig view rather than calling $this['view'] inside controller / anonymous function.

$app->get('/hello/{name}', function ($request, $response, $args) {
    $this['view']->render('profile.html', [
        'name' => $args['name']
    ]);
})->setName('profile');

The idea is even if we are using a different framework, we can make use of the code without changes.

Adding Content-Type description

New users often seem confused regarding how slim populates params()/get()/post(). Content-Type application/json isn't supported by default, and users have been posting to a route with json data and not receiving anything from request->post().

We should improve the documentation with examples on how to correctly POST application/json data to a slim route, and now to receive that data.

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.