zend framework 2 view public function - php

I have read many entries and tried a lot (for example, viewhelpers), but unfortunately nothing works (which is definitely due to my little knowledge). We use the Zend Framework 2 internally with CdliTwoStageSignup (https://github.com/cdli/CdliTwoStageSignup). In this module i want to realize that you can only register if a specific date has not been exceeded. This is currently hardcoded, but should now work with a value from the sql database. This value is already used by other modules, but I do not get it in the module CdliTwoStageSignup. Otherwise, nothing is changed on the module. Unfortunately, I have little idea of php and Zend.
hardcoded looks like this: for submission_deadline a date is manually inserted at the moment
this is from module/CdliTwoStageSignup/view/email-verfication/form.phtml
<?php
if (time() < strtotime($this->submission_deadline)) {
print '<h2>Step 1: <small>Email Verification</small></h2>';
} else {
print '<h2>Step 1: <small>Email Verification (disabled)</small></h2>';
}
Because I have little idea of the framework, I searched in other modules and found that in a view/index.phtml:
<?php
//deadlines
if($this->activeSemester){
$submission_deadline = $this->activeSemester->getDtSubmissionDeadline();
}
Can I use that?
This is a public function in /otherModule/Entity/otherModule.php
public function getDtSubmissionDeadline() {
return $this->dtSubmissionDeadline;
}
So in conclusion is my question: How can I use the variable in this module, what is my problem? I have tried solutions from similar issues, but unfortunately nothing worked. If anything is missing, I'll be happy to complete it.
Thank you very much for your help!

Related

Learing laravel and have problem with getURLList();

Im trying to learn Laravel framework and having trouble with getURLList();
In the tutorial that im following it says.
class StudInsertController extends Controller
{
public function insert(){
$urlData = getURLList();
return view('stud_create');
}
But the getURLLIST(); comes back as
Call to undefined function App\Http\Controllers\getURLList()
And i dont find any information about that.
Is it because the tutorial is for older version of Laravel?
The link to the tutorial itself is here:
https://www.studentstutorial.com/laravel/insert-data-laravel
Can somebody point me in the right direction.
I would have written this as a comment, but I don't have enough reputation.
From what the tutorials says, there are just a few files that you need to touch which effectly means they are not adding a custom helper method.
After looking at the code, I don't see any use for the line of code getting the URLs. It would have been useful if you were to pass the data forward to your view.
So I would recommend you remove the line $urlData = getURLList();. It should work just fine. I don't know if the author left it there by error.

PHP migration 5 to 7, advice on what to check

I have a big system that needs to migrated from php5 to php7. I have found tool PHP Code Fixer that helped me finding all the deprecated function and I fixed them all. But there is another thing that causes problem. I have found in the code a lot of people were returning function call in a function, something like this.
function test($array) {
return reset(callSomeArray($array));
}
This will fail as reset function expects a variable as a parameter. In php5 this worked but not in php7. This is correct way:
function test($array) {
$callArray = callSomeArray($array);
return $callArray;
}
Since this is a big software, and I cannot read the all code and test everything. I found out that reset function is causing the problem, but how to find other function that are used the same. Is there some document, or checklist, what to check for migration. Like, list of functions that expect a variable?

Is there an alternative to the "filter_var" function in php when using HHVM?

I have been recently playing around with HHVM. Went through a lot of trouble getting it to work on my computer. I know that not all PHP functions are available. As a test, I am writing a new website using it instead of using my current code. I ran into a problem when trying to use
filter_var($var,FILTER_SANITIZE_URL);
From the error.log file, it turns out that this function is undefined. Is the filter_var function not available for use in HHVM or am I just doing something wrong here. I like to keep things DRY, this would mean I have to do a lot more validation than I expected.
filter_var is now implemented in hhvm. Open github issues if you have any problems with it.
This function appears to not have been implemented on HHVM See http://comments.gmane.org/gmane.science.linguistics.wikipedia.technical/70038
An option if you want to rely on this functionality with the hopes that it will enter the fold is to polyfill it in (partial implementation to inspire the motivated).
if (!function_exists("filter_var")){
// define the constants used by the function
define("FILTER_VALIDATE_EMAIL", "email");
function filter_var(){
$args = func_get_args();
// $args[1] is the filter type (second parameter)
switch ($args[1]){
case FILTER_VALIDATE_EMAIL:
if (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $args[0])?$args[0]:false;
break;
}
}
}

TinyMVC always shows 'default' controller

I was following documentaion till the end, tested one html template with smarty and then cut it. Then I found out that controllers do not work as expected – whatever name I create in myapp/conrollers, 'hello.php' for example, that contains class described in docs, i. e.
class Hello_Controller extends TinyMVC_Controller
{
function index()
{
echo "Hello World.";
}
function time()
{
echo "The time is now.";
}
}
I can’t show it. So the name of the file is a prefix for the controller class name, all seems to be ok here, but going to /index.php/hello returns what is in 'default.php'. I’ve even tried to change default controller to 'hello' in myapp/configs/application.php by setting $config['default_controller'], but the framework behaves like if it’s always work with the 'default.php'. There is no errors on screen or in logs (I checked twice every option in configs of my web server and interpreter), I totally don’t know what to do with that goddamn piece of crap, I can’t even write on its forum because waiting for ‘administration approval’ for several days.
I had to dig inside of the framework to find an answer. And it is when it checks for a controller file it uses file_exists() which do not respect include path. Googling ‘TinyMVC+file_exists’ gave me link to that topic, where is written that they had fixed it in SVN version.

"Cannot be resolved as a type"

I'm using "Eclipse" and with a simple test code like that one :
class Example {
public static function isStatic() {
return "808";
}
}
class App {
public static function isTest() {
return Example::isStatic();
}
}
But I dont know why but Eclipse still telling me that "Example" in "return Example::isStatic();" cannot be resolved as a type. Why ? It's like a gag.
I try to search a solution in the SO's website but i have not find any answer that work.
If you have any hint that could help, you are welcome :)
EDIT : I'm made a little change in my question because in my previous example, you could use self and that worked fine but in the end, that did not really solve my problem. That one is more accurate to my problem
For those looking for an answer, I find the problem by myself.
In fact, I was using Eclipse Photon and this software is still in beta... I download it thinking it was already release.
I try the same manipulation with Eclipse Oxygen and everything working fine :)
Thank all for your answer and have fun developping.

Categories