Skip to content

Commit

Permalink
Update code examples to use Smarty\Smarty and autoload instead of req…
Browse files Browse the repository at this point in the history
…uire_once calls and new Smarty
  • Loading branch information
wisskid committed Feb 6, 2023
1 parent cf84802 commit 7a323b7
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ looping over a PHP iterator instead of an array().

```php
<?php
include('Smarty.class.php');
use Smarty\Smarty;

$smarty = new Smarty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Variables assigned from PHP are referenced by preceding them with a dollar

```php
<?php

use Smarty\Smarty;
$smarty = new Smarty();

$smarty->assign('firstname', 'Doug');
Expand Down
6 changes: 5 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Here's how you create an instance of Smarty in your PHP scripts:
<?php

require 'vendor/autoload.php';
use Smarty\Smarty;
$smarty = new Smarty();
```

Expand All @@ -44,7 +45,7 @@ The defaults can be changed as follows:

```php
<?php

use Smarty\Smarty;
$smarty = new Smarty();
$smarty->setTemplateDir('/some/template/dir');
$smarty->setConfigDir('/some/config/dir');
Expand Down Expand Up @@ -73,6 +74,8 @@ You can verify if your system has the correct access rights for
these directories with [`testInstall()`](./programmers/api-functions/api-test-install.md):

```php
<?php
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->setTemplateDir('/some/template/dir');
$smarty->setConfigDir('/some/config/dir');
Expand Down Expand Up @@ -106,6 +109,7 @@ Now lets edit our php file. We'll create an instance of Smarty,

require 'vendor/autoload.php';

use Smarty\Smarty;
$smarty = new Smarty();

$smarty->setTemplateDir('/web/www.example.com/guestbook/templates/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Smarty\_Security class or create an instance of it.

<?php

use Smarty\Smarty;

class My_Security_Policy extends \Smarty\Security {
public $allow_constants = false;
}
Expand All @@ -95,6 +97,7 @@ Smarty\_Security class or create an instance of it.


<?php
use Smarty\Smarty;
$smarty = new Smarty();
$my_security_policy = new \Smarty\Security($smarty);
$my_security_policy->allow_constants = false;
Expand All @@ -104,7 +107,7 @@ Smarty\_Security class or create an instance of it.


<?php
require 'Smarty.class.php';
use Smarty\Smarty;
$smarty = new Smarty();
// enable default security
$smarty->enableSecurity();
Expand Down
2 changes: 1 addition & 1 deletion docs/programmers/api-functions/api-compile-all-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ parameters:

<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

// force compilation of all config files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ parameters:

<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

// force compilation of all template files
Expand Down
2 changes: 1 addition & 1 deletion docs/programmers/api-functions/api-create-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ be used to control which variables are seen by which templates.


<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

// create data object with its private variable scope
Expand Down
2 changes: 1 addition & 1 deletion docs/programmers/api-functions/api-create-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ following parameters:


<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

// create template object with its private variable scope
Expand Down
2 changes: 1 addition & 1 deletion docs/programmers/api-functions/api-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PARAMETER.COMPILEID


<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(true);
Expand Down
5 changes: 4 additions & 1 deletion docs/programmers/api-functions/api-register-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ otherwise. If security is enabled, classes registered with


<?php
use Smarty\Smarty;

class Bar {
$property = "hello world";
Expand All @@ -44,12 +45,14 @@ otherwise. If security is enabled, classes registered with


<?php
use Smarty\Smarty;

namespace my\php\application {
class Bar {
$property = "hello world";
}
}

$smarty = new Smarty();
$smarty->registerClass("Foo", "\my\php\application\Bar");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugin types.


<?php

use Smarty\Smarty;
$smarty = new Smarty();
$smarty->registerDefaultPluginHandler('my_plugin_handler');

Expand Down
2 changes: 1 addition & 1 deletion docs/programmers/api-functions/api-test-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ installation can be accessed. It does output a corresponding protocol.


<?php
require_once('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->testInstall();
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource.

<?php

use Smarty\Smarty;
$smarty = new Smarty();
$smarty->default_config_handler_func = 'my_default_config_handler_func';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource.

<?php

use Smarty\Smarty;
$smarty = new Smarty();
$smarty->default_template_handler_func = 'my_default_template_handler_func';

Expand Down
4 changes: 2 additions & 2 deletions docs/programmers/caching/caching-custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ to invoke your custom CacheResource implementation.

<?php

require_once 'libs/Smarty.class.php';
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->caching_type = 'mysql';

Expand Down Expand Up @@ -198,7 +198,7 @@ to invoke your custom CacheResource implementation.

<?php

require_once 'libs/Smarty.class.php';
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->caching_type = 'memcache';

Expand Down
2 changes: 1 addition & 1 deletion docs/programmers/caching/caching-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ structure that mimics your template file structure, such as


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
Expand Down
6 changes: 3 additions & 3 deletions docs/programmers/caching/caching-multiple-caches.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameter to the function call.


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
Expand Down Expand Up @@ -47,7 +47,7 @@ Be sure to pass the same `$cache_id` as the second parameter to


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
Expand All @@ -70,7 +70,7 @@ the first parameter to [`clearCache()`](#api.clear.cache).


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
Expand Down
10 changes: 5 additions & 5 deletions docs/programmers/caching/caching-setting-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The first thing to do is enable caching by setting


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

// uses the value of $smarty->cacheLifetime() to determine
Expand Down Expand Up @@ -41,7 +41,7 @@ setting [`$caching`](#variable.caching) to


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

// retain current cache lifetime for each specific display call
Expand Down Expand Up @@ -75,7 +75,7 @@ This is a computational overhead, so for optimum performance set


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
Expand All @@ -101,7 +101,7 @@ process.


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
Expand Down Expand Up @@ -133,7 +133,7 @@ files [and groups](#caching.groups) with the


<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
Expand Down
4 changes: 3 additions & 1 deletion docs/programmers/plugins/plugins-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ example.

<?php

use Smarty\Smarty;

/**
* MySQL Resource
*
Expand Down Expand Up @@ -107,7 +109,7 @@ example.
}


require_once 'libs/Smarty.class.php';

$smarty = new Smarty();
$smarty->registerResource('mysql', new My_Resource_Mysql());

Expand Down
4 changes: 3 additions & 1 deletion docs/programmers/resources/resources-custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ on the functions you are supposed to provide.

<?php

use Smarty\Smarty;

/**
* MySQL Resource
*
Expand Down Expand Up @@ -93,7 +95,7 @@ on the functions you are supposed to provide.
}


require_once 'libs/Smarty.class.php';

$smarty = new Smarty();
$smarty->registerResource('mysql', new My_Resource_Mysql());

Expand Down
4 changes: 3 additions & 1 deletion docs/programmers/resources/template-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ on the functions you are supposed to provide.

<?php
use Smarty\Smarty;


/**
* MySQL Resource
Expand Down Expand Up @@ -103,7 +105,7 @@ on the functions you are supposed to provide.
}


require_once 'libs/Smarty.class.php';

$smarty = new Smarty();
$smarty->registerResource('mysql', new My_Resource_Mysql());

Expand Down

0 comments on commit 7a323b7

Please sign in to comment.