How to add a new menu/submenu page in WPMVC? [closed]
IT Nursery
May 16, 2022
0
I’m completely new to WPMVC. Followed and finished their tutorial for creating plugins. Now I’m trying to add a search page to search Venues (that comes from their example!). This page should appear as a submenu page of the Venues menu. I created a file named search.php in the app/views/admin/venue/search folder. What should I do now? Googling didn’t help much!
Any help regarding this (and any other stuff a noob should learn to get better with WPMVC) is welcome!
2 Answers 2
Finally after a lot of digging into the core files, I found the way to add a submenu page. Here’s the stepwise solution if anyone is stuck on it!
Lets assume you want to add a submenu page called ‘Sample’.
1.First, in the app/config/bootstrap.php file (you have to manually create it if it doesn’t exist) of your plugin, add the following code. This will add the new page as a submenu of the venues parent menu item:
<?php
//sample is appended to the venues array, meaning it will be a submenu page of venues
MvcConfiguration::append(array(
'AdminPages' => array(
'venues' => array(
'add',
'delete',
'edit',
'sample'
)
)
));
?>
2.Next, in the app/controllers/admin/admin_venues_controller.php add the following function. Notice it is named sample, same as the page name in the array above.
function sample() {
//this array will be available as $values in the sample.php file
$vals = array('great' => 'Done', 'nice' => 'Finally');
$this->set('values', $vals);
}
3.Now the actual page content file, create a sample.php (notice the name) file in the app/views/admin/venues/ folder.
<?php
echo '<h2>'.MvcInflector::titleize($this->action).'</h2>';
//remember the values variable set in the controller?
foreach($values as $i => $val){ ?>
echo $i.' = '.$val;
}
?>
That’s pretty much it! I’m still stuck on creating a top level menu page without having to create a model (models get top level pages by default). Will update this answer when I solve it!
Note: Emailing Tom Benner, the creator of WPMVC didn’t help too! 😉