Tinkerwell background image
Tinkerwell Logo Tinkerwell

Table Mode

The Table Mode of Tinkerwell allows you to see the results of your code in a table and export it to a CSV file. This is extra useful if you pair it with complex database queries for reports that you don’t generate that often or just on demand – no fiddling around with SQL but simply using the ORM of your application.

For the sake of simplicity, we’re using Laravel to explain how it works but your can head to examples for other frameworks if you use them more often. So don’t skip the Laravel examples if you aren’t using the framework but go through them for a better understanding of the Table Mode of Tinkerwell.

Examples

Laravel Example

Laravel Eloquent is a powerful ORM that has a fluent syntax. In this example, we query our Beyond Code database to get a list of all users who bought at least one video course and list them with their course so that we know which email address has access to a specific course.

Laravel takes care out the relation between the User and Course models automatically and makes it easy for us to select the elements from the collections via the mapping method.

Wordpress example

Tinkerwell allows you to get a lists of all posts of your WordPress site and other things easily. In this example, we’re using the `wp_get_recent_posts()` method to get an array of the recents posts and display it in the Table View. You can also use methods like `get_posts()` but they require a transformation into a plain array to get displayed properly.

The Table View is only able to display arrays that have named keys like `ID` and `post_title` in the example but can’t convert WordPress objects (i.e. `WP_Post`) to a list view automatically.

Symfony example

Symfony uses Doctrine as ORM to fetch database records and it works similar to the Laravel example above. You can get the EntityManager for your model – in our example we want to fetch some users and display them and their email addresses in the Table View. You can easily use this as a base example and extend it for your more complex application.

Tinkerwell exposes the `$container` and `$kernel` variables to the editor to make interacting with your application easier.

$users = $container
  ->get('doctrine.orm.entity_manager')
  ->getRepository(App\Entity\User::class)
  ->findAll();

array_map(function ($user) {
  return [
    'full_name' => $user->getFullName(),
    'email' => $user->getEmail(),
  ];
}, $users);

As you can see, the Table View mode is helpful when running custom reports against your application and don’t want to fiddle around with MySQL queries or adding code to your codebase for a task that only happens once.

Tinkerwell: The code runner for PHP

The must-have companion to your favorite IDE. Quickly iterate on PHP code within the context of your web application.

Learn more