Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

how to set property in smarty {$obj->a = 1}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sm@rty
Smarty Regular


Joined: 01 Oct 2014
Posts: 65

PostPosted: Sun Mar 15, 2015 1:11 pm    Post subject: how to set property in smarty {$obj->a = 1} Reply with quote

hi

why smarty not allow to set property of object ?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Mar 15, 2015 2:36 pm    Post subject: Reply with quote

Smarty is a template engine.
Not a programming language.
Stop using it as such.
Back to top
View user's profile Send private message
sm@rty
Smarty Regular


Joined: 01 Oct 2014
Posts: 65

PostPosted: Mon Mar 16, 2015 8:32 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Mar 16, 2015 1:50 pm    Post subject: Reply with quote

Do PHP work in PHP code. And leave template work to template.
Problem solved.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Mar 17, 2015 1:49 am    Post subject: Reply with quote

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
View user's profile Send private message
sm@rty
Smarty Regular


Joined: 01 Oct 2014
Posts: 65

PostPosted: Fri Mar 20, 2015 11:10 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Mar 20, 2015 3:37 pm    Post subject: Reply with quote

I know at least one such source.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP