thanks in advance for any help. I am new to using classes & functions with php so i'm not quite sure how to go about doing this. I have a list that forms an array and I want to reference it across multiple classes / functions without having to call the list every time. Here is the code I have been working with. How can I put the list & array in a global format that I can use to reference the list in other classes & functions?
class article {
public static function data(){
list($articles, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => whereRecordNumberInUrl(0),
'loadUploads' => true,
'allowSearch' => false,
'loadCreatedBy' => true,
'limit' => '1',
));
$article = @$articles[0]; // get first record
if (!$articles) { dieWith404("Record not found!"); } // show error message if no record found
echo $article['article'];
}
}
If you want to use list and article as global var you just have to declare them in the body of your code and declare it in your function as global.
<?php
$article = null;
public static function data()
{
global $article;
$article = ...;
$b = $a + $b;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.