jimfog Posted December 13, 2011 Share Posted December 13, 2011 In my code what i usually do is create divs and inside of them echoing a variable which in turn, has been passed the html code. The variable is included with the usual command in the script. Recently though i came across with another coding scheme. Passing the html in a function and subsequently calling it in the script, after(as the case above) including in the script the file that contains the functions library. I wonder, which coding scheme is better and why, what do you think? Or it is solely a matter of personal preference.? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 13, 2011 Share Posted December 13, 2011 Neither of those really separates the HTML from the PHP. In one case you have PHP variables in the HTML markup, and in the other case it's function calls. If you really want to separate them you'll want to look into a template system. Link to comment Share on other sites More sharing options...
jimfog Posted December 14, 2011 Author Share Posted December 14, 2011 Ok, let us forget the template system and the separation issue for a while. From the two above coding schemes which you think is most appropriate and why. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 14, 2011 Share Posted December 14, 2011 That's a pretty vague description, I don't use either approach, but I guess a function call would be easier to maintain or make changes to in the future. If you used variables and needed to make changes then you would need to change every place the variable gets set instead of the one function. Link to comment Share on other sites More sharing options...
jimfog Posted December 17, 2011 Author Share Posted December 17, 2011 That's a pretty vague description, I don't use either approach... Ok, what do approach do you use, i am trying to fintd the most efficient way to code in PHP. So far function calls seems to me the best. But i want to hear other opinions also. The template system i assume is for complex CMS like joomla ot drupal-so i am not interested for such a solution since i am not building such thing. Link to comment Share on other sites More sharing options...
birbal Posted December 17, 2011 Share Posted December 17, 2011 At the begining i was leaned toward encapsulate in function. But later on i found it is dificult to maintain that later when the aplication began to expand. Then i was look forward to template system like smarty but it seems to me that it is unescecery to get it parse again by template enguine. One of the php feature is php itslelf can be used in html template. MVC like structure will be the best. One for data manupulation and one for visual. In this way you can also separate the backend and frontend which will be effective to maintain and also in collaboration. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 19, 2011 Share Posted December 19, 2011 Ok, what do approach do you use, i am trying to fintd the most efficient way to code in PHP. So far function calls seems to me the best.Well, I use a template system that I made. The code for parsing the templates may be a little inefficient, but it has all of the features I need for the majority of basic websites that I build and it's easy for me to update other sites when I make changes to the template or admin system since they all use the same foundation. Link to comment Share on other sites More sharing options...
jimfog Posted December 19, 2011 Author Share Posted December 19, 2011 Is this template system you use based on MVC? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 19, 2011 Share Posted December 19, 2011 Not formally, but various implementations on different sites have a lot in common with the concept of a MVC architecture. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.