Fatal error due to the "$this" object. (I'm new at this PHP stuff so I need some clarification please.) - this

There's an addon that I used on my Sharetronix website (a microblogging platform for those who aren't familiar with it) which is supposed to allow me to add a page to the root folder of my website. But, I get this message when I go to the page that I just added.
Fatal error: Using $this when not in object context in /home/u556426868/public_html/forum.php on line 2
I've done some research online and I know so much as the "$this" object shouldn't land outside of the "newtemplate_code()" but I don't know what I'm supposed to do in terms of replacing and fixing the code so that the page works.
The code for the whole page is as the following:
<?php
$this->load_template('header.php');
?>
<div id="pagebody" style="margin:0px; border-top:1px solid #fff;">
<div><div id="contacts_left" style="width:100%;"> <div class="ttl">
<div class="ttl2"><h3>iState RPG - The Neovita RPG Forum</h3></div></div>
<br><br>
<center><iframe name=”FRAMENAME” src=”http://istate.serverforumhosting.com/portal.php” width=”1000? height=”1100? frameborder=”1? scrolling=”yes” allowautotransparency=true></iframe></center>
<! REMOVE FROM HERE THE DUMMY CONTENT !>
<b>DOWNLOAD</b> this plugin here(2kb).<br><br>
<center>
<a href="http://sharetronix.com/sharetronix/demo/getfile/pid:public_3965797/New%20Page.rar" target="_blank" title="Download">
<img src="http://wb-cc.de/oscommerce/images/download-1.gif" border="0">
</a><br><br>
Brought to you by iState - The state of you!
</center>
<! REMOVE END !>
</div>
</div>
</div>
<?php
$this->load_template('footer.php');
?>
Like I said, I'm new to PHP coding and so I will need some clarification. So by the way, thanks for helping me!

You are using $this outside a class. I suggest you are trying to use a 3rd party library for templates. First of all you have to include the needed files link this:
include("path/to/your/class.php");
Then you have to find out the name of the class, let's say it starts like this:
class Template
Then you will have to initialise it with
$template = new Template();
and call the needed function
$template->load_template('header.php');
More details about path and usage may be in the installation files of the library.
Oh and $this is only for usage inside classes, e. g.:
class foo
{
function bar()
{
// Do something
}
function do_bar()
{
$this->bar();
}
}

Related

Google Closure Templates variable variables

Situation:
context contains such fields as testExecutionKey1, testExecutionKey2 .. testExecutionKey10
I want to check them for null, but do it the nice way - in for loop
I need to access $context.testExecutionKey1..10 inside the loop, where number is $i
{for $i in range(1, 11)}
{if {$context.testExecutionKey}{$i}}
<div class="aui-message aui-message-info">
<p>A Test instance execution is already linked to this issue: ${context.testExecutionKey{$i}}.</p>
</div>
<input type="hidden" name="skip-test-execution-${$i}" value="true">
{/if}
{/for}
Problem:
PHP has got variable variables feature, but I could no similar find for closure templates in docs.
Reimplementing jira context the proper way is the way to go

Object doesn't support property or method 'igTree' error when running Infragistics Tree Control

I am trying to set up a tree view using an entity framework data object (EF 6 in MVC 5). I've run into a problem when I try to Render() my tree.... I receive the 'Object doesn't support property or method 'igTree'' error.
My code to set up the tree (in my view):
#(Html.Infragistics()
.Tree()
.Bindings(bindings =>
{
bindings.
TextKey("L1Name").
PrimaryKey("L1TODSID").
ValueKey("L1TODSID").
ChildDataProperty("L2Name").
Bindings(b1 =>
{
b1.
TextKey("L2Name").
ValueKey("L2TODSID").
PrimaryKey("L2TODSID");
});
})
.DataSource(Model)
.DataBind()
.Render()
)
I get no errors until I add in the 'Render()' call.
I read a post on the Infragistics forum asking if they will be supporting MVC 5... Are they not doing that? Is that my issue?
Also, these are my calling scripts:
<!-- Ignite UI Required Combined CSS Files -->
<link href="#Url.Content("~/igniteui/css/themes/infragistics/infragistics.theme.css")" rel="stylesheet" />
<link href="#Url.Content("~/igniteui/css/structure/infragistics.css")" rel="stylesheet" />
<script src="#Url.Content("~/Scripts/modernizr-2.7.2.js")"></script>
<script src="#Url.Content("~/Scripts/jquery-2.0.3.min.js")"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.10.3.min.js")"></script>
<!-- Ignite UI Required Combined JavaScript Files -->
<script src=#Url.Content("~/igniteui/js/infragistics.core.js")></script>
<script src=#Url.Content("~/igniteui/js/infragistics.lob.js")></script>
#(Html.Infragistics()
.Loader()
.ScriptPath("~/igniteui/js/")
.CssPath("~/igniteui/css/")
.Render()
)
Thanks in advance!
EDIT: Final Resolve.
Just in case anyone else ever runs accross this situation...
I knew this error ('Object doesn't support property or method...') could be caused by jquery loading twice. Thought I had thoroughly checked all script calls. However, being new to .NET and MVC 5 (razor), I completely missed this line at the end of my layout page (I didn't set up the project originally):
#Scripts.Render("~/bundles/jquery")
So...
In the end, I was initiallizing JQuery in my script block at the top (with a call to the minified file), then I was calling it again, which is what caused the error.
A big thanks to #nemesv, because the fact that he explained the loading process in greater detail than I could find online gave me the confidence to know that I was doing things correctly on that side. Then I just needed to hunt down the second call to initialize JQ.
Thanks again!
By default (if you are not using the loader infrastructure)
The .Render() call will render the following HTML:
<script type="text/javascript">
$(function () {$('#Tree1').igTree({ dataSource: ... });});
</script>
So you get the exception on the igTree function call which would initialize the tree.
Your igTree function can be undefined:
If you are not loading the necessary igniteui scripts:
<script src=#Url.Content("~/igniteui/js/infragistics.core.js")></script>
<script src=#Url.Content("~/igniteui/js/infragistics.lob.js")></script>
Make sure that these scripts are included in your view or in your Layour file
If you are not using the rigth path or the scripts file are not there on the server:
Check for broken link in your browsers network console (F12 in IE/Chrome FireBug in FF):
If you 404 error next to your script you will know that they are not loaded correctly and you need to fix the paths.
If you are referencing jQuery more than once can cause this error too:
Foe example you have the <script src="#Url.Content("~/Scripts/jquery-2.0.3.min.js")"></script> in a partial which is loaded by Ajax multiple times, etc.
Make sure that you are referencing all your scripts once.
In the case of using the loader
When using the Loader infrasturure the .Render() call will render the a different HTML:
<script type="text/javascript">
$.ig.loader('igTree', function() {$('#Tree1').igTree({ dataSource: });});
</script>
So the loader will load the necessary script required by the tree so you don't need to include infragistics.core.js and infragistics.lob.js.
When using the loader in theory you could not the get the exception.
But if you call: #(Html.Infragistics().Loader()... after your Html.Infragistics().Tree() then the MVC wrapper does not that you are using the loader so it renders the HTML like when you don't use the loader so if you rightfully not referenced the infragistics.core.js and infragistics.lob.js. then you get the exception even if you are "using" the loader.
So make sure that you call #(Html.Infragistics().Loader()... before using any of the Infragistics controls.
I was also facing the same issue with MVC 4 and Ignite UI. Removing #Scripts.Render("~/bundles/jquery")
from the _Layout.cshtml resolved the issue.

Incorporate jenkins environment variables into groovy template for email notification

I have several environment variables defined for a project on jenkins, amongst which i want to incorporate some onto the email notification sent before and after build success.
But groovy.text.Template does not seem to accept these environment variables.
I have also used "Inject environment variables to the build process Help for feature: Inject environment variables to the build process" and defined my variable as follows
BUILD_NAME=${BUILD_NAME}
where BUILD_NAME is accepted as a parameter while i execute the build.
Please could someone help me on this.
If you are using the email-ext Jenkins plugin to send out emails, there is a "build" object that contains a lot of information about your Jenkins job.
I would do the following:
Print out the properties inside this object by adding the following code to your template:
<% println build.properties.collect{it}.join('<br />') %>
View the email template output. You can either use the Jenkins "Email Template Testing" feature or just run your job. You should see a whole bunch of "KEY=VALUE" print outs.
Look for the environment variable you are interested in. If your environment variable is listed in environment={BUILD_NUMBER=45, BUILD_DISPLAY_NAME=#45...}, you can just call build.environment['BUILD_NUMBER'] to get 45.
If you want to inject custom environment variables I would suggest installing the Env Inject Plugin, defining your variables through that plugin and then looking for the variable in build.envVars
It seems you can try this
template.make(build.environment)
Source
Hopefully I understood your question, but in order to read that parameter in the template you need to call it like this (if BUILD_NAME is a parameter in the jenkins job:
${ENV, var="BUILD_NAME"}
This will return the value of that parameter.
You can do something like this to get it working
<td style="color: #153643; font-family: Arial, sans-serif;font-size: 14px;padding: 20px 0px;" width="60%">
<%= build.envVars['JOB_BASE_NAME'] %>
</td>
build.envVars has all the env variables as a dictionary. Use key value pair to access the variables.
Just do:
<% def env = build.environment %>
<% def name = env.build_name %>
<% if (name != "") { %>
Name: <%=name %>
<% } %>

How to produce php+html in haxe

I would like to product php code within HTML with heXa. For example:
<?php
$temp = 'Hello';
?>
<html>
<body>
<?php echo $temp?>
</body>
</html>
How would I write the above using haxe? The haxe site shows you how to produce PHP code, but it doesn't mention how to produce PHP with HTML.
Haxe isn't a scripting language that can be called from within a html file in that way. You have to adapt a workflow where you prepare your html templates and your data as separate units and let the compiled application combine them according to your wishes.
Here's a quick example that should work in any Haxe server target language (php, neko, cpp). (Maybe also java and c# - not sure if the Template implementation is ready) :
package ;
import haxe.Template;
import neko.Lib;
class Main
{
static function main()
{
var data = { greeting: 'Hello' };
var template = new Template('<html><body>::greeting::</body></html>');
var output = template.execute(data);
Sys.print(output);
}
}
There are a bunch of template engines for Haxe out there, for example the .NET Razor clone Erazor

Requirejs add arguments to the script element

is it possible to add arguments to the sctipt element
e.g.
<script
...
src="XX.js"
></script>
i want to add the argument hello="world" so this is added to the page:
<script
...
src="XX.js"
hallo="welt"
></script>
Reason: I have a js library (aloha-editor) which depends on a parameter for loading it's plugins (and the main functionallity is actuall in a plugin). However I only want to load the plugin when the user want's to edit and requirejs is the best choice since it is used at other parts in the application.
If you are wrapping the aloha script in a define function you could pass arguments like this (link):
//in main appfile
require.config({
'config': {
'aloha': {
src: "XX.js",
hallo: "welt"
}
}
});
//and in the aloha file
define(['module'], function (module) {
var src = module.config().src,
hallo = module.config().hallo;
... // the aloha code
});
There was also an alternative "simplified" syntax in the docs.
Edit: Maybe I misunderstood the question, if you where asking if it's possible to add html attributes to a script tag already on the page: <script src='' data-src='xx.js' data-hallo='welt'></script> is the new html5 syntax for adding custom attributes to tags, everything preceded by data- is correct syntax.

Resources