dodmax
Forum Replies Created
-
@thebigbanik There is an extra step with ACF Gallery: you need to click the wrench icon and select the gallery name.
screenshot: https://prntscr.com/q5dbke
Also make sure that “Return Format” is set to “Image Array” under this field’s settings in ACF.
You can try to write your own function to query this list in your model and do some tweaking on the find function:
For example in your Book model:
public function get_book_list() { return $this->find(array( 'additional_selects' => array('AuthorBook.rank'), 'joins' => array('Author'), )); }
I’m not sure about the alias given to the table, worst case print the SQL query first to make sure of it.
You can customize your request even more if needed:
$this->find(array( 'selects' => array(...) 'joins' => array( 'table' => '...', 'on' => 'Author.id = ...', 'alias' => 'Author', 'type' => 'LEFT JOIN' ) 'conditions' => array(...) //or sql string ));
Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] belongs_to_dropdown does not populateAS far as I know you have to provide the list yourself to the belongs_to_dropdown() function.
The way to do it is to override the add and the edit functions in your admin controller and to query it there then use set_object to make it available in the view (where the belongs_to_dropdown call is).
Have a look at the event-calendar-example for an example:
\plugins\events-calendar-example\app\controllers\admin\admin_events_controller.phpDoes your database contain a “name” field for this table?
You will most likely have to change the “add” and “edit” forms in views/admin !
Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] code generation utility wpmvc throwing errorAre you sure register_argc_argv is on?
Did you try to print_r($argv) at the top of core/wpmvc.php to make sure of it?Forum: Plugins
In reply to: [WP MVC] plugin won't work without wp-mvc activatedGlad it worked.
But keep in mind that if someone installs wp-mvc (for another plugin) while your plugin is activated it’s gonna break the WordPress installation (Fatal error cannot redeclare class XXX).
Removing therequire 'wp_mvc.php'
should be enough to fix it. Worth throwing a note about it in your read_me ??Forum: Plugins
In reply to: [WP MVC] Does wp-mvc support shortcode and widget ?I can confirm that Davelopware patch works well!
Also although it doesn’t seem to be documented, wp-mvc can automatically register widgets for you.
Just create a
my-plugin/app/widgets
folder and create a php file for each widget, for examplemy_widget.php
.Each file should contain a class following the wordpress widget documentation
Also your widget class name needs to follow the following naming convention: CamelPluginName_CamelWidgetFileName
In the previous example your class would be named
MyPlugin_MyWidget
Only public controllers have the pagination() method.
I guess you could callpaginate_links($pagination);
directly.Forum: Plugins
In reply to: [WP MVC] plugin won't work without wp-mvc activatedIt’s not really a problem, more of a requirement.
Your plugin needs WP-MVC to be loaded in order to work.I guess you could try to bundle your plugin and wp-mvc together so wp-mvc won’t show in the plugin tab.
Try moving the content of the wp-mvc folder in your plugin folder (so you will have my-plugin/core) and add
require 'wp_mvc.php'
on top of your my_plugin.php file.This won’t work if you have more than one plugin using wp-mvc though.
Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] accessing associated models in viewHi davelopware,
Glad that I could help! No extensive testing on my side yet, have to work really quickly for now ??
I like WP-MVC, it lacks some features but it’s an amazing piece of work and it works well.
It’s true that there is some interesting hacks on Github. Hope we’ll be able to put together a comprehensive pull request and that the author will take some time to examine it!Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] accessing associated models in viewHad this problem too, have a look here:
It doesn’t work with $includes though, I’m having an error on my side (looks like a bug, didn’t took time to dive in yet).
Also in the future if you use has_and_belongs_to_many associations and try to get the value via __get() you might wanna apply this patch since there is a bug in v1.2
https://github.com/DODMax/wp-mvc/commit/27db4e6d0b579aba8175cdf63f54700dc4dba50a
Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] accessing associated models in viewActually it should query the value automagically for you since $object has a __get() overload that does it for you.
Just access it like this:$object->jungle_branch->name;
Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] Models: multiple join on the same tableOk after a lot of try and fail I figured out part of it.
Taking the example of a match between 2 teams.The Match model will contain:
var $belongs_to = array( 'Hometeam' => array('foreign_key' => 'home_team_id', 'class' => 'Team'), 'Awayteam' => array('foreign_key' => 'away_team_id', 'class' => 'Team') );
‘class’ => ‘Team’ refer to the Team model name.
The keys of the belongs_to array (‘Hometeam’, …) must have the first letter capitalized, rest lowercase, no underscore or other stuff.The Match admin controller will contain:
var $default_columns = array( 'hometeam' => array('value_method' => 'admin_column_hometeam'), 'awayteam' => array('value_method' => 'admin_column_awayteam'), ); public function admin_column_awayteam($object) { return $object->awayteam->name; //note that awayteam is lowercased } public function admin_column_hometeam($object) { return $object->hometeam->name; }
Somehow something magic happens when calling
$object->hometeam->name
that will query the team name from the database and set it (you can see that $object->hometeam is not set before the call and is after).I’m still having some trouble populating the team name on the edit form since
var $includes = array('Hometeam');
is causing an error…Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] Accessing other Models from a controllerHere is a little patch that would allow to reference a sub object in the format ‘Venue.name’
wp-content\plugins\wp-mvc\core\helpers\mvc_helper.php line 188
public function admin_table_cell($controller, $object, $column) { if (!empty($column['value_method'])) { $value = $controller->{$column['value_method']}($object); } else { $subs = explode('.', $column['key']); foreach ($subs as $sub) $object = $object->$sub; $value = $object; } return '<td>'.$value.'</td>'; }
You could also patch the header cell function line 171 for the name to display automatically:
public function admin_header_cell($label) { return '<th scope="col" class="manage-column">'.MvcInflector::titleize(str_replace('.', ' ', $label)).'</th>'; }
Forum: Plugins
In reply to: [WP MVC] [Plugin: WP MVC] accessing associated models in viewHi,
Try adding
var $includes = array('JungleBranch');
in your model.
This way it should query it for you.
Also try to print_r($object) somewhere to make sure it is / is not inside.