View.php
11.6 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<?php
namespace Phalcon\Mvc {
/**
* Phalcon\Mvc\View
*
* Phalcon\Mvc\View is a class for working with the "view" portion of the model-view-controller pattern.
* That is, it exists to help keep the view script separate from the model and controller scripts.
* It provides a system of helpers, output filters, and variable escaping.
*
* <code>
* //Setting views directory
* $view = new Phalcon\Mvc\View();
* $view->setViewsDir('app/views/');
*
* $view->start();
* //Shows recent posts view (app/views/posts/recent.phtml)
* $view->render('posts', 'recent');
* $view->finish();
*
* //Printing views output
* echo $view->getContent();
* </code>
*/
class View extends \Phalcon\DI\Injectable implements \Phalcon\Events\EventsAwareInterface, \Phalcon\DI\InjectionAwareInterface, \Phalcon\Mvc\ViewInterface {
const LEVEL_MAIN_LAYOUT = 5;
const LEVEL_AFTER_TEMPLATE = 4;
const LEVEL_LAYOUT = 3;
const LEVEL_BEFORE_TEMPLATE = 2;
const LEVEL_ACTION_VIEW = 1;
const LEVEL_NO_RENDER = 0;
protected $_options;
protected $_basePath;
protected $_content;
protected $_renderLevel;
protected $_disabledLevels;
protected $_viewParams;
protected $_layout;
protected $_layoutsDir;
protected $_partialsDir;
protected $_viewsDir;
protected $_templatesBefore;
protected $_templatesAfter;
protected $_engines;
protected $_registeredEngines;
protected $_mainView;
protected $_controllerName;
protected $_actionName;
protected $_params;
protected $_pickView;
protected $_cache;
protected $_cacheLevel;
protected $_activeRenderPath;
protected $_disabled;
/**
* \Phalcon\Mvc\View constructor
*
* @param array $options
*/
public function __construct($options=null){ }
/**
* Sets views directory. Depending of your platform, always add a trailing slash or backslash
*
* @param string $viewsDir
* @return \Phalcon\Mvc\View
*/
public function setViewsDir($viewsDir){ }
/**
* Gets views directory
*
* @return string
*/
public function getViewsDir(){ }
/**
* Sets the layouts sub-directory. Must be a directory under the views directory. Depending of your platform, always add a trailing slash or backslash
*
*<code>
* $view->setLayoutsDir('../common/layouts/');
*</code>
*
* @param string $layoutsDir
* @return \Phalcon\Mvc\View
*/
public function setLayoutsDir($layoutsDir){ }
/**
* Gets the current layouts sub-directory
*
* @return string
*/
public function getLayoutsDir(){ }
/**
* Sets a partials sub-directory. Must be a directory under the views directory. Depending of your platform, always add a trailing slash or backslash
*
*<code>
* $view->setPartialsDir('../common/partials/');
*</code>
*
* @param string $partialsDir
* @return \Phalcon\Mvc\View
*/
public function setPartialsDir($partialsDir){ }
/**
* Gets the current partials sub-directory
*
* @return string
*/
public function getPartialsDir(){ }
/**
* Sets base path. Depending of your platform, always add a trailing slash or backslash
*
* <code>
* $view->setBasePath(__DIR__ . '/');
* </code>
*
* @param string $basePath
* @return \Phalcon\Mvc\View
*/
public function setBasePath($basePath){ }
/**
* Sets the render level for the view
*
* <code>
* //Render the view related to the controller only
* $this->view->setRenderLevel(View::LEVEL_LAYOUT);
* </code>
*
* @param string $level
* @return \Phalcon\Mvc\View
*/
public function setRenderLevel($level){ }
/**
* Disables a specific level of rendering
*
*<code>
* //Render all levels except ACTION level
* $this->view->disableLevel(View::LEVEL_ACTION_VIEW);
*</code>
*
* @param int|array $level
* @return \Phalcon\Mvc\View
*/
public function disableLevel($level){ }
/**
* Sets default view name. Must be a file without extension in the views directory
*
* <code>
* //Renders as main view views-dir/base.phtml
* $this->view->setMainView('base');
* </code>
*
* @param string $viewPath
* @return \Phalcon\Mvc\View
*/
public function setMainView($viewPath){ }
/**
* Returns the name of the main view
*
* @return string
*/
public function getMainView(){ }
/**
* Change the layout to be used instead of using the name of the latest controller name
*
* <code>
* $this->view->setLayout('main');
* </code>
*
* @param string $layout
* @return \Phalcon\Mvc\View
*/
public function setLayout($layout){ }
/**
* Returns the name of the main view
*
* @return string
*/
public function getLayout(){ }
/**
* Appends template before controller layout
*
* @param string|array $templateBefore
* @return \Phalcon\Mvc\View
*/
public function setTemplateBefore($templateBefore){ }
/**
* Resets any template before layouts
*
* @return \Phalcon\Mvc\View
*/
public function cleanTemplateBefore(){ }
/**
* Appends template after controller layout
*
* @param string|array $templateAfter
* @return \Phalcon\Mvc\View
*/
public function setTemplateAfter($templateAfter){ }
/**
* Resets any template before layouts
*
* @return \Phalcon\Mvc\View
*/
public function cleanTemplateAfter(){ }
/**
* Adds parameters to views (alias of setVar)
*
*<code>
* $this->view->setParamToView('products', $products);
*</code>
*
* @param string $key
* @param mixed $value
* @return \Phalcon\Mvc\View
*/
public function setParamToView($key, $value){ }
/**
* Set all the render params
*
*<code>
* $this->view->setVars(array('products' => $products));
*</code>
*
* @param array $params
* @param boolean $merge
* @return \Phalcon\Mvc\View
*/
public function setVars($params, $merge=null){ }
/**
* Set a single view parameter
*
*<code>
* $this->view->setVar('products', $products);
*</code>
*
* @param string $key
* @param mixed $value
* @return \Phalcon\Mvc\View
*/
public function setVar($key, $value){ }
/**
* Returns a parameter previously set in the view
*
* @param string $key
* @return mixed
*/
public function getVar($key){ }
/**
* Returns parameters to views
*
* @return array
*/
public function getParamsToView(){ }
/**
* Gets the name of the controller rendered
*
* @return string
*/
public function getControllerName(){ }
/**
* Gets the name of the action rendered
*
* @return string
*/
public function getActionName(){ }
/**
* Gets extra parameters of the action rendered
*
* @return array
*/
public function getParams(){ }
/**
* Starts rendering process enabling the output buffering
*
* @return \Phalcon\Mvc\View
*/
public function start(){ }
/**
* Loads registered template engines, if none is registered it will use \Phalcon\Mvc\View\Engine\Php
*
* @return array
*/
protected function _loadTemplateEngines(){ }
/**
* Checks whether view exists on registered extensions and render it
*
* @param array $engines
* @param string $viewPath
* @param boolean $silence
* @param boolean $mustClean
* @param \Phalcon\Cache\BackendInterface $cache
*/
protected function _engineRender(){ }
/**
* Register templating engines
*
*<code>
*$this->view->registerEngines(array(
* ".phtml" => "Phalcon\Mvc\View\Engine\Php",
* ".volt" => "Phalcon\Mvc\View\Engine\Volt",
* ".mhtml" => "MyCustomEngine"
*));
*</code>
*
* @param array $engines
* @return \Phalcon\Mvc\View
*/
public function registerEngines($engines){ }
/**
* Executes render process from dispatching data
*
*<code>
* //Shows recent posts view (app/views/posts/recent.phtml)
* $view->start()->render('posts', 'recent')->finish();
*</code>
*
* @param string $controllerName
* @param string $actionName
* @param array $params
* @return \Phalcon\Mvc\View
*/
public function render($controllerName, $actionName, $params=null){ }
/**
* Choose a different view to render instead of last-controller/last-action
*
* <code>
* class ProductsController extends \Phalcon\Mvc\Controller
* {
*
* public function saveAction()
* {
*
* //Do some save stuff...
*
* //Then show the list view
* $this->view->pick("products/list");
* }
* }
* </code>
*
* @param string|array $renderView
* @return \Phalcon\Mvc\View
*/
public function pick($renderView){ }
/**
* Renders a partial view
*
* <code>
* //Show a partial inside another view
* $this->partial('shared/footer');
* </code>
*
* <code>
* //Show a partial inside another view with parameters
* $this->partial('shared/footer', array('content' => $html));
* </code>
*
* @param string $partialPath
* @param array $params
*/
public function partial($partialPath, $params=null){ }
/**
* Perform the automatic rendering returning the output as a string
*
* <code>
* $template = $this->view->getRender('products', 'show', array('products' => $products));
* </code>
*
* @param string $controllerName
* @param string $actionName
* @param array $params
* @param mixed $configCallback
* @return string
*/
public function getRender($controllerName, $actionName, $params=null, $configCallback=null){ }
/**
* Finishes the render process by stopping the output buffering
*
* @return \Phalcon\Mvc\View
*/
public function finish(){ }
/**
* Create a \Phalcon\Cache based on the internal cache options
*
* @return \Phalcon\Cache\BackendInterface
*/
protected function _createCache(){ }
/**
* Check if the component is currently caching the output content
*
* @return boolean
*/
public function isCaching(){ }
/**
* Returns the cache instance used to cache
*
* @return \Phalcon\Cache\BackendInterface
*/
public function getCache(){ }
/**
* Cache the actual view render to certain level
*
*<code>
* $this->view->cache(array('key' => 'my-key', 'lifetime' => 86400));
*</code>
*
* @param boolean|array $options
* @return \Phalcon\Mvc\View
*/
public function cache($options=null){ }
/**
* Externally sets the view content
*
*<code>
* $this->view->setContent("<h1>hello</h1>");
*</code>
*
* @param string $content
* @return \Phalcon\Mvc\View
*/
public function setContent($content){ }
/**
* Returns cached output from another view stage
*
* @return string
*/
public function getContent(){ }
/**
* Returns the path of the view that is currently rendered
*
* @return string
*/
public function getActiveRenderPath(){ }
/**
* Disables the auto-rendering process
*
* @return \Phalcon\Mvc\View
*/
public function disable(){ }
/**
* Enables the auto-rendering process
*
* @return \Phalcon\Mvc\View
*/
public function enable(){ }
/**
* Resets the view component to its factory default values
*
* @return \Phalcon\Mvc\View
*/
public function reset(){ }
/**
* Magic method to pass variables to the views
*
*<code>
* $this->view->products = $products;
*</code>
*
* @param string $key
* @param mixed $value
*/
public function __set($key, $value){ }
/**
* Magic method to retrieve a variable passed to the view
*
*<code>
* echo $this->view->products;
*</code>
*
* @param string $key
* @return mixed
*/
public function __get($key){ }
}
}