Comments (12)
Hi @jacmgr
the Meta and Page models implement the ArrayAccess
interface, so you can use this model classes (objects) as an array.
from phile.
php 5.3.5; Every time I tried I can't get them to work as arrays. If you can post a 2 liner of getting each page meta data into an array it would help me a lot. Using in the template_registered event, the after_read_file_meta, and after_load_content events. I browsed existing phile plugins but no clue for me.
from phile.
currently I could not test it, but I think the following code should work:
$pages = \Phile\Repository\Page::findAll();
foreach ($pages as $page) {
$metaModel = $page->getMeta();
forach ($metaModel as $metaProperty => $metaValue) {
echo "{$metaProperty}: {$metaValue}";
}
}
from phile.
Sorry way past bedtime here. I used similar code to above and could not get to work. I'll try more tomorrow, but if you get any ideas. THankyou
from phile.
Tried:
if ($eventKey == 'template_engine_registered') {
$pages2 = \Phile\Repository\Page::findAll();
foreach ($pages2 as $page) {
$metaModel = $page->getMeta();
foreach ($metaModel as $metaProperty => $metaValue) {
echo "{$metaProperty}: {$metaValue}";
}
}
}
Got These errors
Strict Standards: Non-static method Phile\Repository\Page::findAll() should not be called statically, assuming $this from incompatible context in C:\xampp\htdocs\phile\philecms\plugins\phileJacWikittenTree\plugin.php on line 48
Fatal error: Call to undefined method PhileJacWikittenTree::getPage() in C:\xampp\htdocs\phile\philecms\lib\Phile\Repository\Page.php on line 72
Then tried:
$pageRespository = new \Phile\Repository\Page();
$pages = $pageRespository->findAll();
foreach ($pages as $page) {
$metaModel = $page->getMeta();
foreach ($metaModel as $metaProperty => $metaValue) {
echo "{$metaProperty}: {$metaValue} <br>";
}
}
No errors but no output
Then tried:
$pages = $data['data']['pages'];
foreach ($pages as $page) {
$metaModel = $page->getMeta();
foreach ($metaModel as $metaProperty => $metaValue) {
echo "{$metaProperty}: {$metaValue} <br>";
}
}
Got No output.
from phile.
newbie at github, didn't mean to close this!
from phile.
Check out this template parser lib. I converted the pages object to an array for the template vars.
https://github.com/PhileCMS/phileTemplateLex/blob/master/lib/Phile/Template/Lex.php#L46
from phile.
yes, my code example was wrong, as the error tells you, the method findAll
is not a static method.
As you can see in the example from James, this code should work:
$pageRepository = new \Phile\Repository\Page();
$pages = $pageRepository->findAll()
foreach ($pages as $page) {
$metaModel = $page->getMeta();
forach ($metaModel as $metaProperty => $metaValue) {
echo "{$metaProperty}: {$metaValue}";
}
}
from phile.
I would recommend using the objects anyway. The amount of time put into converting to an array, at this point, seems like it would have been just as easy to re-write to use objects. The event system is also quite different, which means you will have to replace that code too.
Another note, is that Phile uses a FastCache (when enabled), which caches the Page::findAll()
method. So converting the object to an array, every time, will mean that the cache will never get used. Unless you write in a cache check into the plugin. The reason I had to do it for that template parser, is because that parser didn't support objects.
If you need help converting more plugins we really do want to help. But just hacking a Pico plugin, isn't really the best way to make them work efficiently.
That being said I still need to go back and add the cache service to those template parsers.
I dont want to turn you away from converting all your plugins, I am saying thank you and just giving some advice.
from phile.
No problem. As you see, my post above already tried the newer example you posted. If your intention is that that should work, I believe it does not.
I thought that Phile models implemented the ArrayAccess interface, so you can use this model classes (objects) as an array if you wanted. So if that is not the case, then no problem. But if the intention of the core code was that the above examples should work, well, they did not for me. Does your example snippet actually work for you? If not, then what code should be used to loop through the meta?
Close comment or continue discussion, up to you.
from phile.
I've figured it out. The data that was returned in $page->getMeta()
was protected. You needed to access it via the getAll()
on the returned class from getMeta()
. So here is the working code:
$pageRepository = new \Phile\Repository\Page();
$pages = $pageRepository->findAll();
foreach($pages as $page) {
// getMeta and the getAll returns an array of the data
$metaModel = $page->getMeta()->getAll();
// show me the meta attributes
var_dump($metaModel);
}
It was actually in the example I linked. On this line. I can honestly say that I wasn't quite sure why it wasn't working. But now I can say I understand Phile a little better haha
from phile.
Excellent. That is what I was looking for. I tested and it works for me. I am going to sleep now! Thankyou.
from phile.
Related Issues (20)
- Internal Server Error [SOLVED] HOT 1
- Removing subfolders from links with htaccess HOT 3
- Phile plugins don't install properly using composer HOT 2
- Error when symlinking content directory HOT 2
- [TASK] Release 1.8
- [TASK] Put up phile homepage again HOT 1
- Proposal for further core refactoring HOT 1
- [FEATURE] Set error page as config setting
- [BUG] "composer create-project --no-dev phile-cms/phile" doesn't allow further composer usage
- [FEATURE] Update minimum PHP requirement to version 7.1.0
- [FEATURE] Don't use file cache out of the box HOT 3
- Missing some documentation and project status? HOT 1
- PHP 7.4+ deprecates array_key_exists() on objects HOT 1
- Twig variables HOT 1
- help on contact form plugin HOT 1
- Overriding vendor michelf/php-markdown
- PHP 8 HOT 15
- PHP 8/Phile 2 - Plugin Updates Status & Requests
- Pages without meta block are rendered empty
- PHP 8.2 dynamic properties ErrorException
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phile.