17488 Posts in 4473 Topics by 1978 members
|Go to End|
23 August 2008 at 1:48am Last edited: 23 August 2008 1:49am
My problem is that I use php template and function there that returns for ex. "some text",
and in .ss file when i use <% some_kind_edit_function %>$name_of_function<% end.. %>
"some text" is always writed in the top of html page. Probably I could use html tags and css to position this, but some problems would stay. Has somebody had the same problem. knows how?I want It to be always in place where I wrote It in .ss file.....??
23 August 2008 at 2:13am
Actually if you've got a function in your Controller which returns a string, you can use "$name_of_function" in the associated template without the "<% %>" tags. However, I'm never sure to write that function in the Controller or into the Page so you got to have some fun with try and error.
And regarding to your Text positioned at the top of the page, I don't know if this is the case here, but this usually occcurs when having an echo in your Control-Function, so maybe you check out your PHP-code and your way to use that Control in your template.
23 August 2008 at 12:14pm
yes if you are returning a string from a PHP function echoAString() then make sure it returns rather then echos the string.
FlorianH - all methods that you want to call from templates should be in the controller part of the class. As the Controller is the one that controls the templates. You can put methods in the Page part and call them from the Page_Controller if you need.
23 August 2008 at 4:23pm Last edited: 23 August 2008 4:31pm
Actually, I would recommend putting them in the model class. This is closer to the database and it's easier to manipulate data, while still being able to directly call those functions in the template.
Adding lots of data related methods to the controller gives it too much responsibility for managing data. Also, you run into some issues like having to call $this->dataRecord to get the model record in order to get data from it, when the method could just go on the model instead. The template can still see all those methods on the model class thanks to a handy system called ModelAsController.
This also means you can do this:
$page = DataObject::get_one('Page');
If MyMethod was on the Page class, then it's callable in the above fashion. If it's on the Page_Controller class, you can't call it. This makes it easier to re-use code!
25 August 2008 at 10:24am Last edited: 25 August 2008 9:22pm
My problem was echo function. Thanks a lot. But I return It in function readfile() imported from place that source is not accesible. I will rather use other function to get data, but most important to me was that echo is in the top.Right function was implode().
|Go to Top|