Jump to content

Field Type "PAGE"


Enver
 Share

Recommended Posts

Hello I have field Page Select its possible in output select pages which are selected on any user don't show in select 

example 

Field Page which have inside template addAsset to get all pages related to this template 

Select 

----Asset 1

----Asset 2

----Asset 3

----Asset 4

if i have selected Asset 2 (in template User where is this field) don't show it anymore on select page field to skip it

Select 

----Asset 1

----Asset 3

----Asset 4

Thanks.

Link to comment
Share on other sites

I am doing something like this

$user_select_assets = $pages->find("template=addase");
$borago = $pages->find("template=user, user_select_asset.count!=0")->remove($page);

foreach($borago as $bora) {
    foreach($bora->user_select_asset as $snow) {
        $user_select_assets->remove($snow);
    }
}

return $user_select_assets;
 

but i have some warning

Invalid argument supplied for foreach() in /public_html/wire/modules/Inputfield/InputfieldPage/InputfieldPage.module(116) : eval()'d code on line 5

Link to comment
Share on other sites

This is one of those situations where it would be awfully helpful to really see what's the full context, pages and fields you've got etc. but based on what you've posted here:

That error seems to suggest that your second foreach loop (assuming it's actually on line 5) gets invalid argument, i.e. $bora->user_select_asset isn't something you can iterate with foreach. The main problem here might be the way you're trying to find users; try one of these instead:

// this one:
$borago = $pages->find("template=user, user_select_asset.count!=0, include=all")->remove($page);
// or this one:
$borago = $users->find("user_select_asset.count!=0")->remove($page);

If that doesn't help, I'd suggest that you add a check before second foreach line, where you output something like var_dump($bora)var_dump($bora->user_select_asset) and/or get_class($bora->user_select_asset) just to check what you're actually dealing with.

If echo doesn't work there, try wrapping the command with die() (or writing output to log file, here's one example for implementing that.)

Also: make sure that all your variable and template names are properly written; for an example in your first post you mentioned template name "addAsset", while in your code you're trying to find pages with template "addase". Has the name changed or is it misspelled here?

Link to comment
Share on other sites

Here is a final changes

//template "addassets" is where are assets information (Serial, Model, Name, Make )
//template "user" is for users and this template have field "Page" with name "user_select_asset" where i am using also this code in INPUT > PHP Costume Code.

$assets = $pages->find("template=addassets");
$UserAssets = $pages->find("template=user, user_select_asset.count!=0, include=all")->remove($page);

foreach($UserAssets as $AssetSelected) {
    foreach($AssetSelected->user_select_asset as $userA) {
        $assets->remove($userA);
    }
}

return $assets;
 

in output when i edit a User in field Select Asset "user_select_asset"  i can see all assets and i can select one, ok I selected asset with name "Asset1" good and I save a page, than I go to the second user Page to select other asset related to this user there is still Asset1 but some others now is not showing like Asset5 and 6.

thanks.

 
 
 
 
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...