eZ Community » Forums » Developer » Module with dynamic ViewList
expandshrink

Module with dynamic ViewList

Module with dynamic ViewList

Wednesday 19 February 2014 1:46:39 pm - 2 replies

Is this possible?

$list=array('view1','view2','view3','view4');

foreach {

// check what you get as a $_GET parameter is in the $list if yes save the value in $value

}

$ViewList[$value] = array( etc....

And I want to achieve something like this

www.example.com/mymodule/(dynamic view)

Wednesday 19 February 2014 4:42:52 pm

You can define module with one view:

// extension/mymodule/module.php:
$Module = array(
     "name" => "MyModule",
     "function" => array(
         "script" => "test.php"
         )
     );

Then in the test.php script you can do something like this:

$viewParameters = $Params['Parameters'];
$list = array('view1','view2','view3','view4');
 
// if view not defined in list array redirect to kernel not found
if ( !in_array($viewParameters[0], $list) )
    return $Module->handleError( eZError::KERNEL_NOT_FOUND, 'kernel' );
 
// here goes your code

Now you are able to access your views like this: www.example.com/mymodule/view1 

please note that this will work too
www.example.com/mymodule/view1/param2/param3

So if you want to disable this you'll need to replace if condition with this one:

 if ( count($viewParameters) > 1 || !in_array($viewParameters[0], $list) )

Modified on Wednesday 19 February 2014 4:59:30 pm by Mario Ivancic

Thursday 20 February 2014 9:10:53 am

Thank you, exactly what I wanted happy.gif Emoticon

And as you suggested I can still use the ordered parameters for the /view1/param2/param3 etc?

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from