Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty

This commit is contained in:
Simon Wisselink
2023-02-06 15:18:47 +01:00
parent cf84802072
commit 7a323b7345
21 changed files with 44 additions and 28 deletions

View File

@@ -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;

View File

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

View File

@@ -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();
```
@@ -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');
@@ -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');
@@ -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/');

View File

@@ -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;
}
@@ -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;
@@ -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();

View File

@@ -50,7 +50,7 @@ parameters:
<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;
// force compilation of all config files

View File

@@ -60,7 +60,7 @@ parameters:
<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;
// force compilation of all template files

View File

@@ -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

View File

@@ -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

View File

@@ -30,7 +30,7 @@ PARAMETER.COMPILEID
<?php
include('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;
$smarty->setCaching(true);

View File

@@ -24,6 +24,7 @@ otherwise. If security is enabled, classes registered with
<?php
use Smarty\Smarty;
class Bar {
$property = "hello world";
@@ -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");

View File

@@ -25,7 +25,7 @@ plugin types.
<?php
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->registerDefaultPluginHandler('my_plugin_handler');

View File

@@ -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();
?>

View File

@@ -12,7 +12,7 @@ resource.
<?php
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->default_config_handler_func = 'my_default_config_handler_func';

View File

@@ -12,7 +12,7 @@ resource.
<?php
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->default_template_handler_func = 'my_default_template_handler_func';

View File

@@ -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';
@@ -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';

View File

@@ -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);

View File

@@ -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);
@@ -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);
@@ -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);

View File

@@ -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
@@ -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
@@ -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);
@@ -101,7 +101,7 @@ process.
<?php
require('Smarty.class.php');
use Smarty\Smarty;
$smarty = new Smarty;
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
@@ -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);

View File

@@ -31,6 +31,8 @@ example.
<?php
use Smarty\Smarty;
/**
* MySQL Resource
*
@@ -107,7 +109,7 @@ example.
}
require_once 'libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->registerResource('mysql', new My_Resource_Mysql());

View File

@@ -17,6 +17,8 @@ on the functions you are supposed to provide.
<?php
use Smarty\Smarty;
/**
* MySQL Resource
*
@@ -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());

View File

@@ -26,6 +26,8 @@ on the functions you are supposed to provide.
<?php
use Smarty\Smarty;
/**
* MySQL Resource
@@ -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());