Bonjour,

Je suis en train de tester l'integration de Smarty dans le ZF (http://www.kitpages.fr/zf_integrerSmarty.php).

Dans le tuto Zend de Dev.com, on a des $this->url() dans les pages de template.

J'aimerai utiliser ces $this->url dans mon controlleur pour les initialiser comme variables Smarty , mais ca ne fonctionne pas, il ne trouve pas la propriete correspondante.

Je suis dans mon IndexController, et je fais :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
class IndexController extends Zend_Controller_Action 
{
    function indexAction()
    {
 
    	$this->view->message = "test de message";
    	$this->view->assign("toto",
    	   $this->view->url(array('controller'=>'index',
           'action'=>'ajouter')));
        echo $this->view->render("index/index.phtml");
 
    }
...
L'erreur est la suivante :
Call to undefined method Kitpages_View_Smarty::url()
La classe Kitpage est la suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/*
 * Created on 20 juin 07
 *
 * @author Philippe Le Van (http://www.kitpages.fr)
 * @copyright 2005-2007
 */
Zend_Loader::loadClass("Zend_View_Interface");
 
class Kitpages_View_Smarty implements Zend_View_Interface {
 
    protected $_smarty = null;
    /**
     * Sets the template engine object
     *
     * @return smarty object
     */
    public function setEngine($smarty) {
        $this->_smarty = $smarty;
    }
    /**
     * Return the template engine object, if any
     * @return mixed
     */
    public function getEngine() {
        return $this->_smarty;
    }
 
    public function setScriptPath($path) {
        // nothing to do... in smarty...
    }
 
    /**
     * Assign a variable to the view
     *
     * @param string $key The variable name.
     * @param mixed $val The variable value.
     * @return void
     */
    public function __set($key, $val) {
        if ('_' == substr($key, 0, 1)) {
            require_once 'Zend/View/Exception.php';
            throw new Zend_View_Exception(
                'Setting private var is not allowed',
                $this);
        }
        if ($this->_smarty == null) {
            require_once 'Zend/View/Exception.php';
            throw new Zend_View_Exception(
                'Smarty not defined',
                $this);
        }
        $this->_smarty->assign($key,$val);
        return;
    }
 
    public function __get($key) {
        if ('_' == substr($key, 0, 1)) {
            require_once 'Zend/View/Exception.php';
            throw new Zend_View_Exception(
                'Setting private var is not allowed',
                $this);
        }
        if ($this->_smarty == null) {
            require_once 'Zend/View/Exception.php';
            throw new Zend_View_Exception(
                'Smarty not defined',
                $this);
        }
        return $this->_smarty->get_template_vars($key);
    }
 
    /**
     * Allows testing with empty() and
     * isset() to work
     *
     * @param string $key
     * @return boolean
     */
    public function __isset($key) {
        $vars = $this->_smarty->get_template_vars();
        return isset($vars[$key]);
    }
 
    /**
     * Allows unset() on object properties to work
     *
     * @param string $key
     * @return void
     */
    public function __unset($key) {
        $this->_smarty->clear_assign($key);
    }
 
    /**
     * Assign variables (other method)
     *
     */
    public function assign($spec, $value = null) {
        if (!is_array($spec)) {
            $spec = array($spec=>$value);
        }
        foreach ($spec as $key=>$val) {
            if ('_' == substr($key, 0, 1)) {
                require_once 'Zend/View/Exception.php';
                throw new Zend_View_Exception(
                    'Setting private var is not allowed',
                    $this);
            }
            if ($this->_smarty == null) {
                require_once 'Zend/View/Exception.php';
                throw new Zend_View_Exception(
                    'Smarty not defined', $this);
            }
            $this->_smarty->assign($key,$val);
        }
        return;
 
    }
 
    /**
     * Clear all assigned variables
     *
     * Clears all variables assigned to
     * Zend_View either via {@link assign()} or
     * property overloading ({@link __get()}/{@link __set()}).
     *
     * @return void
     */
    public function clearVars() {
        $this->_smarty->clear_all_assign();
    }
 
    /**
     * Processes a view script and returns the output.
     *
     * @param string $name The script script name to process.
     * @return string The script output.
     */
    public function render($name) {
        return $this->_smarty->fetch($name);
    }
 
    /**
     * Retrieve all view script paths
     * unused (smarty...)
     * @return array
     */
    public function getScriptPaths() {}
 
    /**
     * Set a base path to all view resources
     * unused (smarty...)
     * @param  string $path
     * @param  string $classPrefix
     * @return void
     */
    public function setBasePath($path, $classPrefix='Zend_View'){
    }
 
    /**
     * Add an additional path to view resources
     * unused (smarty...)
     * @param  string $path
     * @param  string $classPrefix
     * @return void
     */
    public function addBasePath($path, $classPrefix='Zend_View'){
    }
 
}
D'avance merci pour vos pistes, gardons en tete que je ne debute pas en PHP mais en Zend ... oui ^^

D'ailleurs, l'initialisation des variables de template n'a rien a faire dans le controlleur non ? Ca serait pas plutot dans la vue ?