|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sm@rty Smarty Regular
Joined: 01 Oct 2014 Posts: 65
|
Posted: Sun Mar 15, 2015 1:11 pm Post subject: how to set property in smarty {$obj->a = 1} |
|
|
hi
why smarty not allow to set property of object ? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Mar 15, 2015 2:36 pm Post subject: |
|
|
Smarty is a template engine.
Not a programming language.
Stop using it as such. |
|
Back to top |
|
sm@rty Smarty Regular
Joined: 01 Oct 2014 Posts: 65
|
Posted: Mon Mar 16, 2015 8:32 am Post subject: |
|
|
yes is true.
but in my system is need.
Code: | <?php
class test{
public $a = 1;
}
function test(){
return new test;
}
?> |
Code: | {$obj = test()}
{$obj->a}{*output is 1*}
{$obj->a = 2}{*syntax error*} |
i can get value of a property but can't set value !
i think this action not relation with template engine or programming language.
i can make a function and I simulated this action.(set property).
but for me question is ! why ? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Mar 16, 2015 1:50 pm Post subject: |
|
|
Do PHP work in PHP code. And leave template work to template.
Problem solved. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Mar 17, 2015 1:49 am Post subject: |
|
|
This is not allowed for good reason.
The setting of values by template code is limited to template variables in the context of the template scope.
Being able to modify properties of objects by the template programmer would break this barrier and could create all sorts of problems and security risks.
If you did to do it it should be done in an controlled environment like plugins. |
|
Back to top |
|
sm@rty Smarty Regular
Joined: 01 Oct 2014 Posts: 65
|
Posted: Fri Mar 20, 2015 11:10 am Post subject: |
|
|
U.Tews wrote: | This is not allowed for good reason.
The setting of values by template code is limited to template variables in the context of the template scope.
Being able to modify properties of objects by the template programmer would break this barrier and could create all sorts of problems and security risks.
If you did to do it it should be done in an controlled environment like plugins. |
no exists source good of writing plugin in smarty(advanced) |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|