mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 17:34:26 +02:00
Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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');
|
||||
|
@@ -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/');
|
||||
|
@@ -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();
|
||||
|
@@ -50,7 +50,7 @@ parameters:
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
use Smarty\Smarty;
|
||||
$smarty = new Smarty;
|
||||
|
||||
// force compilation of all config files
|
||||
|
@@ -60,7 +60,7 @@ parameters:
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
use Smarty\Smarty;
|
||||
$smarty = new Smarty;
|
||||
|
||||
// force compilation of all template files
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -30,7 +30,7 @@ PARAMETER.COMPILEID
|
||||
|
||||
|
||||
<?php
|
||||
include('Smarty.class.php');
|
||||
use Smarty\Smarty;
|
||||
$smarty = new Smarty;
|
||||
|
||||
$smarty->setCaching(true);
|
||||
|
@@ -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");
|
||||
|
||||
|
@@ -25,7 +25,7 @@ plugin types.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
use Smarty\Smarty;
|
||||
$smarty = new Smarty();
|
||||
$smarty->registerDefaultPluginHandler('my_plugin_handler');
|
||||
|
||||
|
@@ -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();
|
||||
?>
|
||||
|
@@ -12,7 +12,7 @@ resource.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
use Smarty\Smarty;
|
||||
$smarty = new Smarty();
|
||||
$smarty->default_config_handler_func = 'my_default_config_handler_func';
|
||||
|
||||
|
@@ -12,7 +12,7 @@ resource.
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
use Smarty\Smarty;
|
||||
$smarty = new Smarty();
|
||||
$smarty->default_template_handler_func = 'my_default_template_handler_func';
|
||||
|
||||
|
@@ -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';
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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());
|
||||
|
||||
|
@@ -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());
|
||||
|
||||
|
@@ -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());
|
||||
|
||||
|
Reference in New Issue
Block a user