Code Monkey home page Code Monkey logo

wp-mvc's Introduction

WP MVC

An MVC framework for WordPress

Description

WP MVC is a WordPress plugin that allows developers to use a MVC framework to create plugins. It is a full-fledged framework with architecture that's similar to that of CakePHP or Ruby on Rails. Developers can consequently use it to rapidly build sites that take advantage of both WordPress's native functionality and all of the many advantages of an MVC framework.

WordPress supports a number of specific content types natively, but setting up custom post types and all of the necessary related functionality (public views, administrative management, associations, etc) is typically more time-consuming than doing the equivalent work in an MVC framework. The resulting code and database structure is significantly less graceful than the MVC equivalent, too.

WP MVC fills this gap. The basic idea is that you create an app/ directory that contains a file structure similar to other MVC frameworks (controllers/, helpers/, models/, views/, etc) and set up models, views, and controllers just as you would in other frameworks. WP MVC runs this code in the context of WordPress (i.e. you can still use all of WordPress's functionality inside of app/). Since WordPress already provides an administrative system, admin actions and views in app/ are run in that context, with WP MVC adding all of the necessary WordPress actions and filters to make this possible without the developer needing to lift a finger. An Administration Menu is automatically created for each model, but it can be customized or omitted.

For more extensive documentation, and to see what WP MVC is capable of, please visit wpmvc.org. Check out the tutorial to see how quickly you can get an app up and running.

If you'd like to grab development releases, see what new features are being added, or browse the source code please visit the GitHub repo.

Installation

  1. Put wp-mvc into the wp-content/plugins directory
  2. Activate the plugin in the "Plugins" menu in WordPress
  3. Make sure that Pretty Permalinks are enabled and working
  4. Either set up one of the example plugins to see how WP MVC works or start creating a plugin using the code generation utility wpmvc:

Setting up one of the example WP MVC-based plugins:

  1. Copy its directory (e.g. wp-content/plugins/wp-mvc/examples/events-calendar-example) into the wp-content/plugins directory (e.g. wp-content/plugins/events-calendar-example)
  2. Activate the plugin in the "Plugins" menu in WordPress

After doing so, you should see administrative menus for each model in WordPress, and you'll be able to browse to URLs like /events/, /events/1/, /venues/, etc to see the public-facing views.

Creating a WP MVC-based plugin

It only takes four simple steps to create a basic WP MVC-based plugin:

  1. Create the initial plugin code using a single command (WP MVC provides a code generation utility)
  2. Write the SQL to create any tables that the plugin uses
  3. Create the initial code for the models, views, and controllers using a single command for each resource
  4. Modify the generated models, views, and controllers to customize the app

For a simple example tutorial on this, please see the tutorial on wpmvc.org.

Frequently Asked Questions

What relation does this have to other MVC frameworks?

WP MVC is a full-fledged MVC framework, but behind the scenes it uses existing WordPress functionality to lessen its footprint and better interface with the parent WordPress application. The developer will not need to know about much of this, though, and may merely treat it as another MVC framework. It draws on concepts and workflows from other MVC frameworks; Rails and CakePHP are the biggest influences, and you may see some of their naming conventions being used.

Is feature X available?

If there's functionality that you'd like to use that isn't implemented in the example plugins or mentioned on wpmvc.org, it may not exist yet. However, if it's something that is widely useful, I'd certainly be willing to implement it myself or to accept any well-written code that implements it. Please feel free to either add a topic in the WordPress forum or contact me through GitHub for any such requests:

wp-mvc's People

Contributors

akamadr avatar aleextra avatar alvinbunk avatar amaneshi avatar ar-general avatar celorodovalho avatar chrissnyder avatar cyberscribe avatar damianoporta avatar davideugenepratt avatar dlundgren avatar fantasy1125 avatar fastzen avatar felipeelia avatar flopperj avatar geertplaisier avatar gkweb avatar grubersjoe avatar gumster avatar jordan-enev avatar konafets avatar lindafurstenberger avatar lwincencik avatar mcmx avatar patrik-csak avatar pcfreak30 avatar samwilson avatar simonvomeyser avatar themaze75 avatar tombenner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-mvc's Issues

Admin menu customization

Hello,
I thought we should give more control on admin menus. At the moment wp-mvc adds a top level menu for each controller. Maybe (I think often) it is not what users want. One solution is to set 'in_menu' => false for each page but it sounds too tedious.

Let suppose we have a configuration like:

MvcConfiguration::set([
    'AdminPages' => [
        [
            'controller' => 'venues',
            'action' => 'index',
            'label'  => 'Venues',                        
            'pages' => [                
                [
                    'controller' => 'venues',
                    'action' => 'new',
                    'label' => 'New venue',                                        
                ],  
                [
                    'controller' => 'other_controller',
                    'action' => 'other_action',
                    'label' => 'Other Label',                                        
                ],                 
            ]
        ],
        [
            'controller' => 'articles',
            'action' => 'show',
            'label'  => 'Articles',                        
            'pages' => [                
                [
                    'controller' => 'comments',
                    'action' => 'show',
                    'label' => 'List of comments',                   
                ],  
            ]
        ],
    ]
]);

As you can see with this configuration we can mix controllers and set what links we really need to show inside the pages array. It is simple.

To work with this kind of configuration I also rewrite add_menu_pages method inside /core/loaders/mvc_admin_loader.php,

public function add_menu_pages() {

        $menuPosition = 12;

        $menuPosition = apply_filters('mvc_menu_position', $menuPosition);

        $adminPages = MvcConfiguration::get('AdminPages');

        foreach ($adminPages as $page) {

            $menuIcon = 'dashicons-admin-generic'; 

            /* check if there is a corresponding model with a menu_icon post type argument */
            try {
                $modelName = MvcInflector::singularize(MvcInflector::camelize($page['controller']));
                $model     = mvc_model($modelName);

                if(isset($model->wp_post['post_type']['args']['menu_icon'])) {
                    $menuIcon = $model->wp_post['post_type']['args']['menu_icon'];    
                }
            } catch (Exception $e) {
                ; //not every controller must have a corresponding model, continue silently
            }

            $controllerTitleized = MvcInflector::titleize($page['controller']);                    
            $topLevelHandle      = 'mvc_' . $page['controller'] . '_' . $page['action'];
            $capability = $this->admin_controller_capabilities[$page['controller']];

            $method = function() use ($page){
              MvcDispatcher::dispatch(['controller' => 'admin_'. $page['controller'], 'action' => $page['action']]);
            };

            add_menu_page(
                $controllerTitleized,
                $controllerTitleized,
                $capability,
                $topLevelHandle,
                $method,
                $menuIcon,
                $menuPosition
            );

            foreach($page['pages'] as $subPage) {

                $method = function() use ($subPage){
                  MvcDispatcher::dispatch(['controller' => 'admin_'. $subPage['controller'], 'action' => $subPage['action']]);
                };  

                $subPageHandle = 'mvc_' . $subPage['controller'] . '_' . $subPage['action'];

                add_submenu_page(
                    $topLevelHandle,
                    $subPage['label'] . ' ‹ ' . $controllerTitleized,
                    $subPage['label'],
                    $capability,
                    $subPageHandle,
                    $method
                );                                
            }  

            $menuPosition++;
        }
    }

Then, I also have removed process_admin_pages because it was no longer called.
What do you think? If you like the idea i will optimize the code and send a PR.

Example error

Hello,
i am tring to run events-calendar-example but i get this error

[MVC] Fatal Error: To associate posts with Speaker, its table needs to have a column named "post_id" of type BIGINT(20). Please run the following SQL to add and index the column:
ALTER TABLE wp_speakers ADD COLUMN post_id BIGINT(20);
ALTER TABLE wp_speakers ADD INDEX (post_id);

Thrown on line 60 of /var/www/wordpress/wp-content/plugins/wp-mvc/core/models/mvc_model.php 

Make an ajax call in WPMVC

I need to use ajax in WPMVC based plugin in wordpress. The tutorial is not helping much in the process. SInce i am new to WP, i need some more help like where to add jQuery, how to link, etc.

Anybody out there, could help me, please?

Thankyou.

WP-MVC is not suitable for high-traffic websites

I have been using this framework as the basis for numerous custom plugins on a high-traffic website and have discovered a bug. Basically, WP-MVC reloads the rewrite rules on every page load, which physically removes and re-adds them from the database with each load. This is warned against in the latest version of the Wordpress documentation as a very bad idea: http://codex.wordpress.org/Function_Reference/flush_rewrite_rules . It means that under high-concurrency traffic spikes, this can result in routes being momentarily unavailable at time of page load, resulting in intermittent 404 errors. In my testing of high-concurrency, this could spike up to 10% of the time, (ab -n 100 -c 10) and has been very difficult and frustrating to diagnose due to the intermittent nature of the problem. My current pull request: #42 addresses this issue. If anyone knows how to reach Tom Benner (I have been trying repeatedly) please let me know, since as it is now the WP-MVC framework from his master branch is not suitable for high-traffic websites. It is otherwise a really great framework, and I would love to see it become concurrency-safe on the master branch.

Q: views folder get's always pluralized even if controller's name is in singular form. Intentional?

I am not sure it's a bug, but for me it seems to be. Maybe someone can enlighten me about this topic.

Is there specific reason behind pluralizing views folder name even though my controller name is in singular form. Let's say my controller name would be "store". I get following error "[MVC] Warning: View "stores/index" not found. "

Right now I fixed "the problem" by just overwriting views path in my controller.. but am I missing something big here? Shouldn't it be by default controllers own name?

class StoreController extends MvcPublicController {
    public function index() {
        $this->views_path = $this->name . '/';
    }
}

-EDIT-

http://wpmvc.org/documentation/utilities/inflector/adding_rules_to_inflector.html
Seems that I could also over-ride some pluralizations- but this is note the case here

mvc_admin_controller create_or_save does not use model primary key

Love your plugin Tom,

Stumbled on what might be an issue. I noticed that the function
mvc_admin_controller create_or_save does not use the model's primary key

This seems to make the administrative edit page fail to update an existing row and creates a new row when primary_key is set to something other than id.

Could be on purpose.

I just might edit line 43 from
if (empty($object['id'])) {
to
if (empty($object[$this->model->primary_key])) {

Thanks much man, be well.

Test in WordPress 3.4

After trying to track down the cause of some errors during my first attempt at this plugin, I noticed that it has only been tested with WordPress versions up to 3.3.X.

Could you test it on WordPress 3.4? (And if it works, update the tested versions in documentation and WP headers?)


If it matters, here is the error Iโ€™m getting.

  • Using WP 3.4.2
  • Using MAMP on OS X (10.8 โ€œMountain Lionโ€)
    • MAMP v1.9 (while writing this I noticed a newer release! I will update MAMP and see if it helpsโ€ฆ)
    • (MAMP) Apache 2.0.63
    • (MAMP) PHP v5.3.2
    • (MAMP) MySQL 5.1.44

After installing the WP-MVC plugin, I:

  • set the environment variables in the Terminal to point to MAMPโ€™s php executable
  • set executable permissions for wpmvc
  • used wpmvc to generate a plugin
  • edited the SQL to create the necessary tables

โ€ฆAnd at this point, I went into the WordPress Admin area and attempted to activate the new plugin. Upon activation, I get errors saying that the plugin generated somewhere between 600โ€“900 lines of unexpected output (the amount varied as I was tweaking things and troubleshooting).

I would much prefer this to organize data than the clunkier processes available in core WordPress. Please let me know if this awesome plugin can be salvaged on my setup! โ˜บ

Fatal error during plugin generation using the wpmvc file

Fatal error: Class 'MvcShellDispatcher' not found in /wp-content/plugins/wp-mvc/core/wpmvc.php on line 8

This is the message I get while trying to generate a simple plugin to test this out under PHP 5.3 et WP 3.5.1

I'll be digging for a solution right now.

Bug in mvc_html_helper.php

Hi,

I found a bug in core/helpers/mvc_html_helpers.php:

public function admin_object_link($object, $options=array()) {
        $url = self::admin_object_url($object, $options);
        $text = empty($options['text']) ? $object->__name : $options['text'];

        return self::link($text, $url);
    }

is missing the $options parameter on self::link thus not returning any other options like 'class', 'style' etc. on links. This is what it should look like:

public function admin_object_link($object, $options=array()) {
        $url = self::admin_object_url($object, $options);
        $text = empty($options['text']) ? $object->__name : $options['text'];

        return self::link($text, $url, $options);
    }

Rendering wrong page or Page not found.

We are using WP MVC plugin to create a project management tool which includes many controllers. Application make some Ajax call to render view of other controller and display content in other sections of page, though we are not using admin-ajax.php or admin_ajax_connect for Ajax request. Sometime while processing request following error occurs :

  1. Page Not Found
  2. Rendering of index page of theme instead of view.

Frequency of error is too high which stuck the whole page. While debugging WP MVC code though FirePHP, I found that 'rewrite_rules_array' filter does not fire and template_redirect filter fail to dispatch request to requested controller's action.

Could anyone give appropriate solution for this issue?

Documentation about using different layouts is misleading?

Problem with this example: http://wpmvc.org/documentation/views/layouts/specifying_a_layout.html

I had error "[MVC] Warning: View "show" not found." But I had that file where it should be by default. In folder views/[my-controller-name]/show.php

when I used code from documentation -

  public function show() {
    $this->render_view('show', array('layout' => 'custom_layout'));
  } 

Am I assuming wrong?

I would recommend to make a notice that you have to give path relative to the "views" folder not assume it will use the one in current controller views folder. Maybe this issue report will help someone out in future :) I wasted almost half an hour digging trough code.

Also there is a easy fix for this.. use this code instead.

    public function show() {
        $this->render_view($this->name . '/show', array('layout' => 'custom_layout'));
    }

You do not have sufficient permissions to access this page

I am using wordpress 4.0, localhost, WP MVC for plugin development.

I have a plugin named W2Store. It has three controllers, Countries, Currencies, Zones.

All the three were mereged into one single admin menu Mystores and the index page is working.
I have added a link to add a new record in each of the controller's page and when i click that link, i get this error.
I tried all methods given in the forums and online helps and still couldn't find a solution to this mess.

Below is the code i have written in w2-store/app/views/admin/layouts/admin.php :

<div class="wrap">

<?php $this->display_flash(); ?>

<?php $controller = $this->name; ?>

<?php $this->render_main_view(); ?>

<?php echo $this->name; ?>

<?php

if($name = 'admin_countries') {
    $controller = 'countries';
    echo '<a href="admin.php?page=mvc_countries-add">Add New</a>';
}
elseif ($name = 'admin_currencies') {
    $controller = 'currencies';
    echo '<a href="admin.php?page=mvc_currencies-add">Add New</a>';

}
elseif ($name = 'admin_zones') {
    $controller = 'zones';
    echo '<a href="admin.php?page=mvc_zones-add">Add New</a>';

}

?>
</div>

can any one suggest me a solution?
Thankyou very much.

WordPress Fatal error: require(): Failed opening required

( ! ) Fatal error: require(): Failed opening required '' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/wordpress/wp-content/plugins/wp-mvc/core/controllers/mvc_controller.php on line 265

I get this above error despite trying so many suggestions in the forums, stackexchange etc.

I developing a plugin in WordPress 4.0.1 using WP MVC, and it also encapsulates ORM concept that is in-built with WP MVC. I couldnt find a solution for this.
Below is the code: (Admin Controller)

/plugins/w2-store/app/controllers/admin/admin_geozone_rules_controller.php


class AdminGeozoneRulesController extends AdminController {

    // Default items in Geozone Rules view
    var $default_columns = array(
                                'id',
                                'Geozone' => array('value_method' => 'admin_column_geozone'),                               
                                'Country' => array('value_method' => 'admin_column_country'),
                                'Zone' => array('value_method' => 'admin_column_zone'),
                                'ordering');

    // Function to add a new record in wp_w2store_geozonerules table
    public function add() {
        $this->set_geozones();
        $this->set_countries();
        $this->set_zones();
        $this->set_geozonerules();      
        $this->create_or_save();
    }

    public function edit() {    
        $this->set_geozonerules();
        $this->set_geozones();
        $this->set_countries();
        $this->set_zones();
        $this->set_object();
        $this->verify_id_param();
        $this->create_or_save();
    }

    // Function to display the Country name Geozone Rules view
    public function admin_column_country($object) {
        return $object->country->country_name; 
    }

    // Function to display the Geozone name Geozone Rules view
    public function admin_column_geozone($object) {
        return $object->geozone->geozone_name;
    }

    // Function to display the Zone name Geozone Rules view
    public function admin_column_zone($object) {
        return $object->zone->zone_name; 
    }

    // Data retreived from four different tables using joins 
    private function set_geozonerules() {

        $this->load_model('GeozoneRule');
        $geozonerules = $this->GeozoneRule->find(array(
                                                'joins' => array(
                                                'Geozone', 'Country', 'Zone'
                                                ),
                                                'includes' => array(
                                                'Geozone', 'Country', 'Zone'
                                                ),
                                                'selects' => array(
                                                                'Geozone.id', 'Geozone.geozone_name',
                                                                'Country.id', 'Country.country_name',
                                                                'Zone.id', 'Zone.zone_name',
                                                                'GeozoneRule.id', 'GeozoneRule.ordering'
    /*                                                          ),
                                                'conditions' => array(
                                                                    'GeozoneRule.geozone_id' => 'Geozone.id',
                                                                    'GeozoneRule.country_id' => 'Country.id',
                                                                    'GeozoneRule.zone_id'    => 'Zone.id'
    */                                                          )
                                                        )
                                                );

        $this->set('geozonerules', $geozonerules);
    }

    private function set_geozones() {
        $this->load_model('Geozone');
        $geozones = $this->Geozone->find(array(
                                        'selects' => array(
                                        'id',
                                        'geozone_name'
                                        )
                                        ));
        $this->set('geozones', $geozones);
    }

    private function set_countries() {
        $this->load_model('Country');
        $countries = $this->Country->find(array(
                                        'selects' => array(
                                        'id',
                                        'country_name'
                                        )
                                        ));
        $this->set('countries', $countries);
    }

    private function set_zones() {

        $this->load_model('Zone');
        $zones = $this->Zone->find(array(
                                    'selects' => array(
                                    'id',
                                    'zone_name'
                                    )
                                    ));
        $this->set('zones', $zones);
    }   

    public function geozonerule_edit_link($object) {
        return empty($object->geozonerule) ? null 
                                            : HtmlHelper::admin_object_link($object->geozonerule, 
                                                array('action' => 'edit'));
    }

    public function geozonerule_view_link($object) {
        return empty($object->geozonerule) ? null 
                                            : HtmlHelper::admin_object_link($object->geozonerule,
                                                array('action' => 'view'));
    }


}

?>

(Public Controller)

/plugins/w2-store/app/controllers/geozone_rules_controller.php


class GeozoneRulesController extends MvcPublicController {

    var $after = array('set_geozonerules');

        public function set_geozonerules() {
            $this->load_model('GeozoneRule');           
            $geozonerules = $this->GeozoneRule->find();
            $this->set('geozonerules', $geozonerules);
        }

        // Overwrite the default index() method to include the 'is_public' => true condition
        public function index() {

        $objects = $this->GeozoneRule->find(array(
                                    'joins'     =>  array('Geozone', 'Country', 'Zone'),
                                    'includes'  =>  array('Geozone', 'Country', 'Zone'),
                                    'selects'   =>  array('Geozone.id, Geozone.geozone_name',
                                                    array('Country.id, Country.country_name',
                                                    array('Zone.id', 'Zone.zone_name',
                                                    array('GeozoneRule.id', 'GeozoneRule.ordering')
                                                    )
                                            )))
                                    );
        $this->set('objects', $objects);

        // pagination
        $this->params['page'] = empty($this->params['page']) ? 1 : $this->params['page'];
        $this->params['conditions'] = array('is_public' => true);
        $collection = $this->model->paginate($this->params);
        $this->set('objects', $collection['objects']);
        $this->set_pagination($collection);

        echo '<a href="admin.php?page=mvc_geozone_rules-add">Add New Geozone Rule</a>';

    }

    // GeozoneRule selects only GeozoneRule names and ids by default; to select all fields from GeozoneRule,
    // we'll overwrite the default show() method
    public function show() {

        $object = $this->model->find_by_id($this->params['id'], array(
            'includes' => array(
                            'Geozone',
                            'Country',
                            'Zone',
                            'GeozoneRule' => array(
                                                'selects' => 'GeozoneRule.*'
                                                )
                            )
                            ));

        if (!empty($object)) {
            $this->set('object', $object);
            $this->render_view('show', array('layout' => 'public'));
        }
    }
}

?>

Model:


class GeozoneRule extends MvcModel {

    var $table = '{prefix}w2store_geozonerules';
    var $primary_key = 'id';
    var $display_field = 'id';
    var $default_order = 'sort_name';
    var $includes = array('Geozone', 'Country', 'Zone');

    var $has_and_belongs_to_many = array(
                        'GeozoneRule' => array(
                                        'join_table' => array('{prefix}w2store_geozones',
                                                            'fields' => array('id', 'geozone_name')),
                                                        array('{prefix}w2store_countries',
                                                            'fields' => array('id', 'country_name')),
                                                        array('{prefix}w2store_zones',
                                                            'fields' => array('id', 'zone_name')),
                                                            'fields' => array('id', 'ordering')
                                                            )
                                        );

    public function after_find($object) {
        if (isset($object->geozonerules)) {
            $geozonerule_names = array();
            foreach($object->geozonerules as $geozonerule) {
                $geozonerule_names[] = $geozonerule->name;
            }
        }

    //  print_r ($object);
    //  exit;
    }

    public function after_save($object) {
        $this->update_sort_name($object);
    }

    public function update_sort_name($object) {

        $sort_name = $object->geozonerule_name;
        $this->update($object->__id, array('sort_name' => $sort_name));
    }


}

?>

Now the error i got:

on line 265 Call Stack Time Memory Function Location . . 11 0.0659 3870616 require( '/var/www/html/wordpress/wp-content/plugins/w2- . .

Fatal error: require(): Failed opening required '' (include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/html/wordpress/wp-content/plugins/wp-mvc/core/controllers/mvc_controller.php on line 265 Call Stack Time Memory Function Location . . 11 0.0659 3870616 require( '/var/www/html/wordpress/wp-content/plugins/w2-store/app/views/admin/layouts/admin.php' ) ../mvc_controller.php:265 . .

Any possible solutions will be of much help. Thanks a lot.

WP-MVC + MySQL Profiler

How to use both together?
I see the error of GeSHI, and replaced the call to the lib inside my plugin, but the queries dont show.

default_selects should be simply selects?

In the __construct() method of MvcModel, we have this line:

'selects' => empty($this->selects) ? array(''.$this->name.'.*') : $this->default_selects,

That seems wrong to me. We're testing for $this->selects, but then using $this->default_selects.
Seems like it should be:

'selects' => empty($this->selects) ? array(''.$this->name.'.*') : $this->selects,

Notice: Undefined Variable - Really can't get my head around this

I'm still learning the ropes of WP-MVC and am stuck in my learning project of a todo-list.
Task belongs to Tasklist, Tasklist has many Task.

This code in my Task Controller:

public function edit(){

        $this->verify_id_param();
        $this->set_object();
        $this->set_tasklists();
        $this->create_or_save();
    }

public function show(){
        $this->set_object();
        $this->set_tasklists();
    }
private function set_tasklists(){

        // Load the Tasklist model
        $this->load_model('Tasklist');

        // Get all the Tasklists
        $tasklists = $this->Tasklist->find(array('selects' => array('id','name')));

        // Set the tasklists to be used in the view
        $this->set('tasklists', $tasklists);
    }

this code in views/tasks/show.php raises no warning and dumps the Tasklists:

Tasklists:
    <?php var_dump($tasklists); ?>

while this code in /views/admin/task/edit.php raises a php warning for 'Notice: Undefined variable: tasklists in .../edit.php':

<?php echo $this->form->belongs_to_dropdown('Select a Tasklist for the task' , $tasklists, array() ); ?>

What am I doing wrong?

Bashing is allowed.

Overwrite mvc_helper.php in WPMVC to modify the default table view in WordPress

I need a helper to change the default view of index page in wordpress.

My plugin is WPMVC generated and as per instructions in the official tutorial of WPMVC, i have created and loaded the helper but it is not working.

Can any one show me the right way to proceed?

screenshot from 2014-12-05 15 43 45

In the above image, the links and button below the records are added by me, overwriting the index file.

Now, i need to add a link near 'Edit | View | Delete' in the image, like,

Edit | View | Add Rule | Delete

Any suggestions on how to do that?

As i have told earlier, i created and loaded the helper but it is not functioning.

Need help. Thanks.

Codes:

 /w2-store/app/helpers/geozone_helper.php (Create Helper):

<?php
class GeozoneHelper extends MvcHelper {

public $_redirect_action = '';

public function __construct() {
    if(empty($this->_redirect_action)) {
        $this->_redirect_action = 'geozone_rules-add';
    }
    parent::__construct();
}

public function admin_actions_cell($controller, $object) {
    $links = array();
    $object_name = empty($object->__name) ? 'Item #'.$object->__id : $object->__name;
    $encoded_object_name = $this->esc_attr($object_name);
    $links[] = '<a href="'.MvcRouter::admin_url(array('object' => $object, 'action' => 'edit')).'" title="Edit '.$encoded_object_name.'">Edit</a>';
    $links[] = '<a href="'.MvcRouter::public_url(array('object' => $object)).'" title="View '.$encoded_object_name.'">View</a>';
    $links[] = '<a href="'.MvcRouter::admin_url(array('object' => $object, 'action' => $this->_redirect_action)).'" title="Edit '.$encoded_object_name.'">Add Rule</a>';
    $links[] = '<a href="'.MvcRouter::admin_url(array('object' => $object, 'action' => 'delete')).'" title="Delete '.$encoded_object_name.'" onclick="return confirm('Are you sure you want to delete '.$encoded_object_name.'?');">Delete</a>';
    $html = implode(' | ', $links);
    return '<td>'.$html.'</td>';
 }
}


 /w2-stores/app/controllers/geozones_controller.php (load helper):

public function show() {

    $object = $this->model->find_by_id($this->params['id'], array(
        'includes' => array('Geozone')));

    if (!empty($object)) {
        $this->set('object', $object);
        $this->render_view('show', array('layout' => 'public'));
    }
    $this->load_helper('geozone');
    $this->set_object();
}


 /w2-store/app/view/geozones/show.php (link to the helper):

 <h2><?php echo $object->__name; ?></h2>

 <p>
    <?php echo $this->html->link('โ† All Geozones', array('controller' =>   'geozones')); ?>
    <?php echo $this->geozone->admin_actions_cell($controller, $object->content); ?>
 </p>

Thanks a lot again.

Help Needed for Customizing Admin Menu and Submenus

Hi there,

Good Day!

I'm seeking for anyone here who can assist me with with WP MVC. I'm trying to customize admin menus and submenus for my plugin. I noticed that every time a controller is created, it creates a menu and submenu for its index which actually has the same name. I want to remove the submenu that has the same name with the top level menu one. I tried configuring that via bootstrap.php, but I'm having a hard time trying to remove that. Any workaround would do as well..

image

Thank you!

custom layouts

I'm still figuring out the code, but it seems to me that the call to render_view on line 38 of mvc_dispatcher.php should pass $options as the second parameter. This way, if someone sets a custom layout in the route table, it'll get properly rendered.

Maybe that's not how it's supposed to work, though.

Support Password Fields in Form Helper

It would be great if there was support in MvcFormHelper for HTML password fields.

Example:

echo $this->form->input('user_pw', array('type' => 'password', 'label' => 'Your Password', 'required' => true));

Or alternatively:

echo $this->form->password('user_pw', array('label' => 'Your Password', 'required' => true));

OSX MAMP php CLI

I ran into this issued and maybe it could be documented somewhere. On OSX if you are using MAMP for development, the command "php" using the shell won't connect to the database because you are running the binary included on the OS.

To fix that, open "wpmvc" included in the plugin and provide the proper route to php

#!/bin/bash
mvc_core_path="$(dirname $0)/core/"
/Applications/MAMP/bin/php5.3/bin/php -q "${mvc_core_path}wpmvc.php" "$@"

Including assets

I'm not seeing in the documentation a methodology for including assets such as js or css files. In the plugin I'm working on right now, I just added the following in bootstrap.php:

wp_register_style( 'plugin-css', mvc_css_url('plugin_name','styles'));
wp_enqueue_style( 'plugin-css');

wp_enqueue_script('plugin-js', mvc_js_url('plugin_name','plugin'),array('jquery'));

Then I placed the files in plug_name/app/public/css and plugin_name/app/public/js. Works great! If this is a sensible solution, might make sense to add this to the documentation.

[MVC] Warning: Undefined property: City::id.

[MVC] Warning: Undefined property: City::name.
Thrown on line 192 of /var/www/html/wordpress/wp-content/plugins/wp-mvc/core/helpers/mvc_helper.php

I get this message when i view the plugin main menu in the side bar.

How to recover from it and what is the possible cause of this error?
and whenever i try to add a record i get the following message:

Add City

[MVC] Fatal Error: Field "code" not found for use in a form input.
Thrown on line 5 of /var/www/html/wordpress/wp-content/plugins/cities-world/app/views/admin/cities/add.php

please guide me in this regard..
Thankyou.

Prabhu.

screenshot from 2014-11-03 16 41 08
screenshot from 2014-11-03 16 41 39

render_view silent error

Hi friend, I use this plugin and its awesome helped me out with all my ajax requests. I have an issue though, thats kind of obscure and I can't seem to debug it.

The problem is that at random interval when performing a call (via jquery ajax) to a controller the response returns the whole homepage of the site and doesn't render the partial thats hooked.

I've been trying to fix this with no success the error happens randomly but occassionaly. Please if you can provide some insight in how to go about fixing this let me know, if you need more details i'll try to explain better.

'Id' coloumn in any table needs to be 'id' only and not table specific

Hello Tom,
there is a problem i face in naming conventions of table columns. I created a table name 'wp_w2store_countries' in the database 'w2store' having an auto_increment primary key column as 'country_id'. When i try to add data using form input, it works fine. But when i try to edit the record, the field 'country_id' is not bound and mapped since the convention doesn't allow it, and the record is not updated.

I tried hard and in the end, i compromised to alter the column to be 'id' and now the CRUD operations work fine.

Over writing of WP MVC methods, reassigning or replacing of '__id' to some other variable were not possible in this case and is that the limitation of WP MVC?

If one has multiple number of tables like countries, currencies, zones etc., one may want to name the columns of the table in a unique manner viz., country_id, currency_id, zone_id etc. But this limitation seems to be a bit tiresome and may result in confusion and ambiguity, i guess.

Your advice is sought in this regard.
Thank you.

Avoid Controllers creating admin pages.

I'm creating a few controllers that don't require backend pages, hence my controllers/admin folder is empty. How can I prevent it from adding the backend pages?

Creating new plugin via shell

Hello
we can not create plugin via command. This is the result:

bash wpmvc generate plugin PluginName
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 79
PHP Notice:  Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80

Notice: Undefined index: HTTP_HOST in /var/www/wordpress/wp-content/plugins/dynamic-hostname/dynamic-hostname.php on line 80
PHP Fatal error:  Call to undefined function is_plugin_active() in /var/www/wordpress/wp-content/plugins/wp-mvc-a8fe1631aa3f091c058aa6c62303c40bfee55188/core/wpmvc.php on line 9

Fatal error: Call to undefined function is_plugin_active() in /var/www/wordpress/wp-content/plugins/wp-mvc-a8fe1631aa3f091c058aa6c62303c40bfee55188/core/wpmvc.php on line 9
[root@wordpress wp-mvc-a8fe1631aa3f091c058aa6c62303c40bfee55188]# 

@cyberscribe I am using your PR.

WP MVC - metabox functionality

I am developing wordpress plugin. I need to use metabox for certain needs. How can i accomplish this using WP MVC? Currently i am using the wordpress add_meta_box() function in the main file of the plugin. Since this is specific to a particular model, i need to rearrange the code accordingly.

// Add meta box
function example_add_box() {
    global $meta_box;
    global $post;
    add_meta_box($meta_box['id'], $meta_box['title'], 'example_product_box', $meta_box['page'], $meta_box['context'], $meta_box['priority'],'add_my_meta_box');
}

And I have added too many lines of coding for box definition, register post type, save box data etc..

I need to simplify the coding and achieve the very purpose of using the WP MVC framework. Can anyone help me in this regard? Thanks.

How to force reload rewrite rules during dev?

It seems like adding new routes in routes.php only takes effect after deactive / active the plugin.

During development, it's quite annoying, is there a workaround to force a reload of the rewrite rules?

I have tried things like calling load_plugin_routes() or this:

require_once MVC_PLUGIN_PATH.'core/loaders/mvc_public_loader.php';
$public_loader = new MvcPublicLoader();
$public_loader->init();
$public_loader->load_rewrite_rules();
$public_loader->flush_rewrite_rules();

But I got this error:

Fatal error: Call to a member function add_query_var() on null in /code/wordpress/wp-includes/rewrite.php on line 47

Thanks for your help

Feature: filter bar in admin

It would be great to have a filter bar to filter on various fields in the admin. This would make it much more useful for implementations with a lot of records.

PHP Warning while creating the tutorial plugin

Hi,

first of all thank you for the plugin. I've just begun fiddling with it but find the idea excellent.
I followed the site tutorial on WP 3.5.1 and created the Venue Listing plugin.
I get this warning in the admin view when viewing "Venues":

Warning: Creating default object from empty value in /Users/lucatume/Dropbox/Developer/WebDeveloper/vhosts/wordpress.dev/wp-content/plugins/wp-mvc/core/controllers/mvc_controller.php on line 110

this seems not to be an obstacle to the functions of the plugin but still merits an issue raising.
Tried following the tutorial 3 times to be sure and the warning always comes up.

Luca

Making generated plugins independent

I'm loving this plugin right now, and pushing hard to get it implemented at my company. One thing that would make it much easier would be to remove the dependency on wp-mvc from generated plugins (I could run the plugin locally without making any mention of it to anyone, and just ship code as I usually would.)

Before I dig into this myself to see how feasible it might be, I figured I'd ask and see if you have considered this before, and what size of a job this would actually be. Any thoughts?

Strict standards: Non-static method MvcRouter::admin_page_param() should not be called statically

Hi!
I report the following problem:
Strict standards: Non-static method MvcRouter::admin_page_param() should not be called statically, assuming $this from incompatible context ....

Description problem:
at line 7 of file "root_directory/wp-content/plugins/wp-mvc/core/pluggable/views/admin/index.php", a call is made to the method "admin_page_param" of that class "MvcRouter". The method "admin_page_param" of the class "MvcRouter" instead is declared as no static.

Shortcode to load controller

Is it possible to add shortcode:
[wp-mvc plugin="plugin_name" controller="controller_name" method="method_name" parameters="parameters_list"]
Thanks.

I am not able to create new action in admin controller

Hi,
I want to add new action in admin controller but i am not able to access new action through url.

ex: i have created view' action
class AdminEventsController extends MvcAdminController {
public function view() {
echo 'in view';
}
}
when i am accessing throgh this url:
http://localhost/dish/wp-admin/admin.php?page=mvc_venues-set_test

i am getting below error
You do not have sufficient permissions to access this page.

i am admin of my test website.

fatal error

Hi there

just starting with wp mvc hoping my skills in codeigniter help to work faster in wp... anyway, firstly I did found that underlines in table names is a bug in wp mvc... so, just avoid using them to solve the matter, secondly after creating the plugin and generating the models, views and controller, I'm getting this fatal error:

Fatal error: Call to a member function paginate() on a non-object in /home/centrote/public_html/wp-content/plugins/wp-mvc/core/controllers/mvc_admin_controller.php on line 83

what should I do?

thanks

events-calendar-example activation issue

I try to activate events-calendar-example and got this:

[MVC] Fatal Error: To associate posts with Speakers, its table needs to have a column named "post_id" of type BIGINT(20). Please run the following SQL to add and index the column:
ALTER TABLE wp_speakers ADD COLUMN post_id BIGINT(20);
ALTER TABLE wp_speakers ADD INDEX (post_id);

Integrating with posts

Hi, I am wanting to use WPMVC instead of custom post types to have more flexibility on admin layout and have custom fields. I did read on the docs that there is wordpress integration data and I'm wondering if the process would be something like this or if there is a better approach:

-create new WPMVC plugin
-on the admin controller I would pull in both my plugin model and wordpress post model (MvcPost)
-on the admin view I would display fields from both models
-on save admin controller would save both models

This seems really simple, but its more of a theory I haven't actually done it yet. My question is, will this allow me to use wordpress post functions to pull in my wpmvc plugin data as well for a widget? Would I need to use hooks for that? Any thoughts?

Thanks!

Is it ok to override views_path?

By inspecting your code I have found that you automatically look for templates in a folder using a pluralize version of the model name.

In my case, my controller is not bound to a specific model, and the default behavior is to look into a folder named registers. In order to fix this, I have override the property views_path (see below), but was wondering if it is ok, or if it could lead to unexpected behavior since this property is not declared as such in the MvcController class.

class RegisterController extends MvcPublicController
{
    public function __construct()
    {
        parent::__construct();
        $this->views_path = 'register/';
    }
}

Thanks for your help!

Stand-alone feature?

Hello,
what do you think about creating a stand-alone version of this framework ?
At the moment a plugin that uses this framework needs wp-mvc as dependence (a different plugin that must be downloaded and activated) what about if we incorporate it?

Customizing admin menu in WP MVC

I have a plugin named W2Store. For this plugin, i generated scaffold viz., Country, Currency, Zone.
By default, i have three main menus, namely, Countries, Currencies, Zones in the dashboard menu. But i need to restructure these menus like this(all three embedded into one menu 'W2Store'):

W2Store -> Countries -> Add, Edit, Delete
W2Store -> Currencies -> Add, Edit, Delete
W2Store -> Zones -> Add, Edit, Delete

I searched the net to find a solution and there i got one with the same objective but it is not working.

eagerfish.eu/customizing-admin-menus-which-are-created-by-Wordpress-mvc-plugin/

i dont know why. may be the version of the WP-MVC resulted in the conflict since the then version of WP-MVC was 1.2.(Sep' 2012)

Since I couldn't find any directives in the documentation, I chose to ask you.
Please do the needful.
Thankyou verymuch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.