Problems passing data to view using PRADO - php

I've been given a website to maintain. The website is using PRADO framework and I had to do some minor changes. There were no problems with the HTML and CSS changes, but now I have to pass some data from a page to a view.
I've tried using:
$this->HomeCalendar2->DataSource = $result['data'];
$this->HomeCalendar2->dataBind();
but it says Component property 'Home.HomeCalendar2' is not defined.
Above my code there is the following code:
$this->HomeCalendar->DataSource = $result;
$this->HomeCalendar->dataBind();
and it works perfectly fine and I can't see where is the definition of HomeCalendar.
Any help will be appreciated.
P.S: I've never worked with PRADO before.

This question is quite old now, hope you already solved it.
Using DataSource means that there must be in your template (.page or .tpl) a TDataBoundControl component like the folowwing (using TRepeater for example)
<com:TRepeater ID="HomeCalendar">
<!--- [ properties like ItemTemplate here and it contents ] --->
</com:TRepeater>
Subclasses of TDataBoundControl are for component needing to loop results, (sorts of for or foreach somehow).
If you juste need to pass a signle result to the view you can use a component like TPanel/TActivePanel, TLiteral, etc. or simply use the expression tag.
Examples :
Expression tag :
Php :
<?php
$this->myvalue = 'Hello World!';
Template :
<h1><%= $this->myvalue %></h1>
Or another solution:
Template :
<com:TLiteral ID="MyLiteral" />
PHP :
<?php
$this->MyLiteral->getControls()->add('<h1>Hello world !</h1>');

Related

How do I use Joomla article variables inside modules?

For getting the article alias of the current/active article, I can use
<?php echo $article->alias;?>
This will work fine if I put that code inside the article itself.
However when I put this code inside a Joomla module, it echos nothing;
Not even when I insert the module inside the article itself (with Modules Anywhere from Regular Labs).
How can I make use of the Joomla variables (or this one in particular) within a module?
Many thanks!
For now I have found an alternate solution that seems to give me the desired result.
<?php $alias=basename($_SERVER['REQUEST_URI']);?>
<?php echo $alias;?>
This apparently returns the last part of an URL string (everything behind the last slash).

How to write Angular/React-like PHP Components

I wrote a PHP Class that works by constructing a paginator by passing it a current page value and a number of pages to show value like this:
$paginator = new Paginator(1,4);
then I out put it like this
<?php
require_once("./partials/pagination.php");
?>
... tons of html
<?php
$paginator = new Paginator(4,2 );
echo($paginator->paginator)
?>
I'd love to be able to simplify it down to something like
<?php
<Paginator pageNum='1' numToShow='3' />
?>
anyone have any thoughts on how this might be done? Other than writing a parser.
This project must be done in PHP for a variety of reasons or I would use react/angular. If anyone has any tips on how to write a "Componentized" php front end, i'd love to hear.
(Needs to be served statically, so I cannot use JS for this)
Thanks
Why not just separate logic of instanciating paginator and view layer? You'll finally get just this:
<?= $paginator->paginate(2,4); ?>

What could cause something like that ? PHP - MYSQL failure

Firstly i want to explain how my script works..
I'am using script named TSUE and source code protect by ioncube. Script has own plugins system kind of like vbulletin's Addons system. For using this system i need to create new php function to get data from database and i need to create a template for use(show) them as i want.
I created very simple plugin sample code. I'm getting tid and added coloum in tsue_torrents table with this function;
and using by this template i can show this data which page i want!
here is template
(template name is example btw. need to call that template using by eval in function)
<div class="widget">
<h4>Plugins Example</h4>
<br />
{$output}
</div>
Everything is look fine
But when i add this plugins on my main page or anypage of script I getting error like this;
��\IsG�>��%x!��n�(.���d)D�94��]J��]�$A����4a}�.sҍ��z_VU/ #��/��#-�YYY�U�w��|������~�ܦ�Lz���ѷk����SK�z��н� �ч�v)7�q�m"���u�c&O:�$B�����Nm���œ �m6OOO<!І�/rP�V�5��f�� �s%�#;�� �4MT*S_t���=�����n������˷��7��D�Lw���4S�l�w�%#u��� Ⱥ/����p?�S�s�]�?o �c_�=�~*�u4�]��/*�'B-<[�<�T�ϓ�J'S`�>w�*?s���/�1K�ߩ�9j$:_��F<���O:��g~G79��~t���1��8�|��$��b?��H�T����L:)pq�C���P�4����Ӑ�+G|(zC�C�&�8�:�����9je)!����$�1�)�g1��p�B���̐g!-��N���D*' �Q*�o5�NJ<'%Ha��v,#A_$<���φ2��F�z.O�0J$��&.k,����6]�M�'9��&B#��*�4���Yʾ�Q�i� ���A�P��yV�n��ݴ��tJ?�&8�mO�h�3�ד(Jk�h��iVY��8v��Ô��k��Gˌ����B���b�5�"}��g��c>��vU�}���.l�:h��� `k��4KB=Ȃo�K 0QCz##=;���k�& 7m�+�Q4n�"m�I��E��x�>>�zNO���Ta�M䉆�H�}��v9k�Ӫ���a+�+��#��R����=h7-�H�����R�S�3�a���O�zݨʜ�Ԩu�Ғ��ԮL�mI>i��#�n��f��Juj�=_��0<��zyj�U�9�Z�k�y��H��J�0>����'8L�Z?K�(��QF�B7�������E�uB:�$�i����m�hV�F��AHU�փ� �,�!��wjZ�U��6�pH8y��#OOe� c��5C��\�ɼ :�.���Q]$�lm����%��I�=� ���C��Р��#O�89Pk5����M����f�]_�cc
Screenshot :
Okay; I found why i get that weird error.
I think it is because Dreamweaver CS6.. I don't know excatly reason but when i type my code another php editor , function work fine..

PHP code in FatFree template

I am trying to work with FatFree framework and trying to use the template engine. I render the template with the following code -
echo Template::serve('template.php');
The problem which I'm facing is that, inside the template.php file the F3 tags are recognised but any PHP code doesn't work. For instance, if I have the following code in the template.php file -
<?php
if (F3::get('var') == 'var1') {
?>
<span>var1 is present</span>
<?php
} else {
?>
<span>var1 not present</span>
<?php
}
?>
Here both var1 is present and var1 not present is printed irrespective of the value of var. Also, php for loops are not working - so basically all the php code is not working.
However, if I used <F3:check> to write the above PHP code, then everything works fine. Can we not use PHP code in templates. If this is the case, this is a serious limitation.
I have found the answer, although I don't really like it.
There is two different functions, F3::render() and Template::serve()
With F3::render() you can evaluate PHP expressions and use the F3::get() to retrieve variables. According to the website: "The only issue with embedding PHP code in your templates is the conscious effort needed to stick to MVC principles"
The Template::serve() is for templating only. Meaning its simply to process the templating language.
So basically, and yes it sucks and doesn't make sense, you can evaluate PHP code in the F3::render() and you can't use templating variables ({{#var}}) -OR- you can use Template::serve() and you are limited to only calling PHP functions, and not truly evaluating PHP code.
Maybe try to use different template engine which will allow you define easier the blocks variable dependency?
For example in PHPTal http://phptal.org/manual/en/split/tal-condition.html you can do it like that:
<div tal:condition="php: var == 'var1'">
....
</div>
It is undocumented but you can put code within {~ ~} in a template and it will be converted to <?php ?> when the template is compiled (using v3.6).
e.g. {~ #color = 'red' ~} will become <?php $color = 'red' ?>

Parse template tags outside of Expression Engine Template

I'm running Expression Engine 2.3.0 and using the Channel Images add on.
Part of the site is complex enough that I'm doing it via a plugin rather than using EE's template logic. What I've essentially got is a CodeIgniter controller and views that's called on the site using an EE template tag that I specify.
I'd like to use channel images to make the channel data I'm displaying in my views look a little nicer. Problem is... the Channel Images function doesn't seem to allow me to call it as PHP. Because of the EE template parameters.
So, I decided I'd try to run a template block through the parser. But I'm not getting a result. Any ideas? Or maybe a workaround to call the function directly?
<?php $this->EE =& get_instance();
$img_tpl = '{exp:channel_images:images entry_id="'. $item['id'] .'" cover_only="yes"}
<div style="float:left; display:inline; width:125px;">
<img src="{image:url:small}" alt="{image:title}" />
<p>{image:description}</p>
</div>
{/exp:channel_images:images}';
$opts = array('');
$img = $this->EE->output->set_output($this->EE->TMPL->parse_variables($this->EE->TMPL->parse_globals($img_tpl), array($opts)));
?>
You're going to have a hell of a time here. No part of EE's front-end parsing is written thinking that it will be called from outside of EE.
parse_variables() and parse_globals() don't parse full EE tag pairs (only individual variables), which is why you're getting no results.
I'd really recommend making this work with EE templates.
https://expressionengine.stackexchange.com/questions/1347
I keep revisiting this answer and would like to add how I solved it in ExpressionEngine 3.
// load my own instance of TMPL as myTMPL
ee()->load->library("template", null, "myTMPL");
// get template as a string, and variables as name => value pairs
$template = ee()->myTMPL->fetch_template("mygroup", "mytemplate", false);
$variables = array("name" => "Mr. John Q. Public");
// render the template
$html = ee()->myTMPL->parse_variables($template, array($variables)); // merges variables
ee()->myTMPL->parse($html); // handles conditionals (doesn't seem to run plugins)
$html = ee()->myTMPL->parse_globals(ee()->myTMPL->final_template); // returns output

Categories