( ! ) Fatal error: require(): Failed opening required '' /mvc_controller.php on line 265
I get this above error despite trying so many suggestions in the forums, stackexchange etc.
I am 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:
(Public Controller)
/app/controllers/geozone_rules_controller.php
<?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 'Add New Geozone Rule';
}
// 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:
<?php
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));
}
}
?>
and now the error i got:
Warning: require(): Filename cannot be empty in /mvc_controller.php
on line 265 Call Stack
Time Memory Function Location . . 11 0.0659 3870616
Any possible solutions will be of much help. Thanks a lot.
Issue solved. Simple error made a lot of fuss.
In views/admin/ folder, there is a folder for the model GeozoneRule in the name 'geozonerules' and it was renamed to 'geozone_rules'. Now it is ok.
Naming of folders and files needs careful attention.
Thanks folks.
Related
I have updated to Wordpress 5.5 and want to remove Yoast from the install as its pretty much only used for sitemaps, however need to create a couple of custom sitemaps based on different post types, which I am currently doing with Yoast.
I am adding a custom provider as seen below which overrides both needed abstract functions. Both of these are working and the new entry is being added to the sitemap index at wp-sitemap.xml
However when clicking on /wp-sitemap-range-1.xml I get resolved with the latest blog post on the site instead of the expected site map with the three post types together.
I cannot find any documentation in the Wordpress API spec or codex yet so am at a bit of a loss at the moment - Any help is appreciated. A link with an example working provider would also be appreciated, as I have searched far to try and find something with no luck.
My next steps to to check all the 404 handlers and rewrite handlers in my theme to see if anything is sending it to the wrong place. I have much more complex sitemaps to produce, but want this one simple aggregation of the three post types to work first.
<?php
//Add provider for post types 'cast', 'keg', 'cider' to create a sitemap called 'range'
add_action('init', function() {
$rangeProvider = new key_sitemapProvider('range', array('cask', 'keg', 'cider'));
wp_register_sitemap_provider('pmrs-range', $rangeProvider);
});
/*---------------------*/
class key_sitemapProvider extends WP_Sitemaps_Provider {
public $postTypes = array();
/*---------------------*/
public function __construct($name, $postTypes) {
$this->name = $name;
$this->postTypes = $postTypes;
$this->object_type = 'post';
}
/*---------------------*/
private function queryArgs(){
return array(
'post_type' => $this->postTypes,
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'post_date',
'order' => 'DESC'
);
}
/*--OVERRIDE-----------*/
public function get_url_list($page_num, $post_type = '') {
$query = new WP_Query($this->queryArgs());
$urlList = array();
foreach($query->posts as $post) {
$sitemapEntry = array(
'chf' => 'weekly',
'pri' => 1.0,
'loc' => get_permalink($post),
'mod' => get_the_modified_time('Y-m-d H:i:s', $post)
);
$sitemapEntry = apply_filters('wp_sitemaps_posts_entry', $sitemapEntry, $post, $post_type);
$urlList[] = $sitemapEntry;
}
return $urlList;
}
/*--OVERRIDE-----------*/
public function get_max_num_pages($post_type = '') {
return 1;
}
/*---------------------*/
}
SOLUTION
Thanks to Matt Jaworski's answer below found a way to get this to work, with couple other issues.
Name property of your WP_Sitemaps_Provider extension needs to match the name you are registering with Wordpress. Also this should not contain any special chars
Supported values in the sitemap entries are : changefreq, priority, loc, and lastmod. This is opposed to the shortened version I had before.
Working Example
/*---------------------*/
add_action('init', function() {
$rangeProvider = new key_sitemapProvidor('range', array('cask', 'keg', 'cider'));
wp_register_sitemap_provider('range', $rangeProvider);
});
/*---------------------*/
class key_sitemapProvidor extends WP_Sitemaps_Provider {
public $postTypes = array();
/*---------------------*/
public function __construct($name, $postTypes) {
$this->name = $name;
$this->postTypes = $postTypes;
$this->object_type = 'post';
}
/*---------------------*/
private function queryArgs(){
return array(
'post_type' => $this->postTypes,
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'post_date',
'order' => 'DESC'
);
}
/*--OVERRIDE-----------*/
public function get_url_list($page_num, $post_type = '') {
$query = new WP_Query($this->queryArgs());
$urlList = array();
foreach($query->posts as $post) {
$sitemapEntry = array(
'changefreq' => 'weekly',
'priority' => 1.0,
'loc' => get_permalink($post),
'lastmod' => get_the_modified_time('Y-m-d H:i:s', $post)
);
$sitemapEntry = apply_filters('wp_sitemaps_posts_entry', $sitemapEntry, $post, $post_type);
$urlList[] = $sitemapEntry;
}
return $urlList;
}
/*--OVERRIDE-----------*/
public function get_max_num_pages($post_type = '') {
return 1;
}
/*---------------------*/
}
I had the same issue, and docs simply don't exist.
Through several trials and errors I figured out most likely WordPress does not like any special chars inside the names.
In my case replacing community-posts with communityposts helped.
Here's the very rough (but working) proof of concept we are working on now:
class PeepSo3_Sitemap_Provider extends WP_Sitemaps_Provider {
private $limit = 10; // #TODO CONFIGURABLE
public function __construct() {
$this->name = 'communityposts';
$this->object_type = 'communityposts';
}
private function sql($page_num) {
$sql =""; // your queries here;
return $wpdb->get_results($sql);
}
// retrieve a page of results
public function get_url_list( $page_num, $object_subtype = '' ) {
$url_list = [];
$posts = $this->sql($page_num);
foreach($posts as $post) {
$url_list[] = ['loc' => $post->url; // depends on your item structure
}
return $url_list;
}
// estimate how many pages are available
public function get_max_num_pages( $object_subtype = '' ) {
$posts = $this->sql(-1);
return ceil($posts[0]->count_posts/$this->limit);
}
}
// Register XML Sitemap Provider
add_filter('init', function() {
$provider = new PeepSo3_Sitemap_Provider();
wp_register_sitemap_provider( 'communityposts', $provider );
});
I am learning Mediawiki and looking at some of the extensions.
Manual:$wgUser on mediawiki.org states the global variable $wgUser should not be used for new code.
Manual:RequestContext.php says the context object should be used instead, by using either $this->getUser() or $context->getUser().
However, when I try to use $this->getUser()->getName() in the extension for Who's Online I get the following error:
Fatal error: Using $this when not in object context in /home/ghsfhaco/public_html/wiki/extensions/WhosOnline/WhosOnlineHooks.php on line 19
And when I change it to $context->getUser()->getName() I get this error:
Fatal error: Call to a member function getUser() on null in /home/ghsfhaco/public_html/wiki/extensions/WhosOnline/WhosOnlineHooks.php on line 19
The full Extension:WhosOnline can be found at Mediawiki, but here's the specific page:
class WhosOnlineHooks {
// update online data
public static function onBeforePageDisplay() {
global $wgUser;
// write to DB (use master)
$dbw = wfGetDB( DB_MASTER );
$now = gmdate( 'YmdHis', time() );
// row to insert to table
$row = array(
'userid' => $wgUser->getId(),
'username' => $wgUser->getName(),
'timestamp' => $now
);
$method = __METHOD__;
$dbw->onTransactionIdle( function() use ( $dbw, $method, $row ) {
$dbw->upsert(
'online',
$row,
array( array( 'userid', 'username' ) ),
array( 'timestamp' => $row['timestamp'] ),
$method
);
} );
return true;
}
public static function onLoadExtensionSchemaUpdates( $updater ) {
$updater->addExtensionUpdate( array( 'addTable', 'online',
__DIR__ . '/whosonline.sql', true ) );
return true;
}
}
How exactly should it be done?
BTW, I'm using Mediawiki 1.28.0.
From the page you linked (Working with Request Contexts > When using hooks): If your hook provides an OutputPage as an argument make use of the context provided by it. BeforePageDisplay does provide an OutputPage, so just use its getUser() method.
I'm actually working on a Helper for CakePHP3 that include BsHelper and then the BsFormHelper.
Actually everything looks good, no problem with Bootstrap formats.
I try now to create a ckEditor instance, but I meet some several problems.
If i try to call my ckEditor like this :
$this->BsForm->ckEditor('test')
I just have some problems because the function ckEditor is in my BsFormHelper, and load function is in BsHelper. So when i try to access private var to know if i had to load ckEditor i got that issue :
Error: Call to a member function load() on a non-object
File C:\wamp3\www\wac_lucien\BsHelpersCakePHP3\3.2\plugins\BsHelpers\src\View\Helper\BsFormHelper.php
So in fact I know where is the issue :
In BsFormHelper my fonction looks like :
public function ckEditor($fieldName, $options = array(), $ckEditorOptions = array()) {
$options['type'] = 'textarea';
$out = $this->input($fieldName, $options);
// If there is a point in the fieldName
if (strpos($fieldName, '.') !== false) {
$nameForReplace = Inflector::camelize(Inflector::slug($fieldName));
} else {
$nameForReplace = $this->_modelForm . Inflector::camelize($fieldName);
}
$this->Bs->load('ckeditor');
$this->Bs->loadJS('CKEDITOR.replace("' . $nameForReplace . '", ' . json_encode($ckEditorOptions) . ');', true);
return $out;
}
And in my BsHelper i got :
public function load($key) {
if (!$this->__extensions[$key]['loaded']) {
foreach ($this->__extensions[$key]['css'] as $css) {
$this->loadCSS($css);
}
foreach ($this->__extensions[$key]['js'] as $js) {
$this->loadJS($js);
}
$this->__extensions[$key]['loaded'] = true;
}
return $this->__extensions[$key]['loaded'];
}
Values are in declaration like this
public $__extensions = array(
'jasny' => array(
'css' => array(
'//cdnjs.cloudflare.com/ajax/libs/jasny-bootstrap/3.1.3/css/jasny-bootstrap.min.css'
),
'js' => array(
'//cdnjs.cloudflare.com/ajax/libs/jasny-bootstrap/3.1.3/js/jasny-bootstrap.min.js'
),
'loaded' => true
),
'ckeditor' => array(
'css' => array(),
'js' => array(
'//cdn.ckeditor.com/4.5.8/standard/ckeditor.js'
),
'loaded' => true
)
);
Can someone help me to find out ? It looks like load function called in BsFormHelper can't access privates vars from BsHelper ...
seems you are just trying to use a helper in another helper
The manual says
You may wish to use some functionality already existing in another
helper. To do so, you can specify helpers you wish to use with a
$helpers array, formatted just as you would in a controller:
So in your BsFormHelper just do
public $helpers = ['Bs'];
and you're done
I am adding a mass action to add a category. I am most of the way there I only have one function left to figure out.
Clr\Categorymassaction\controllers\Adminhtml\Catalog\ProductController.php
class Clr_Categorymassaction_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Controller_Action
{
public function massCategoryAction()
{
$productIds = $this->getRequest()->getParam('product');
$cat = $this->getRequest()->getParam('Category');
if (!is_array($productIds)) {
$this->_getSession()->addError($this->__('Please select product(s).'));
$this->_redirect('*/*/index');
}
else {
$cat = $category['label']->getCategoryId();
foreach($productIds as $product) {
//Process $cat into categoryId append categoryId to $productId
$cat->setPostedProducts($product);
}
//Save product
$cat->save();
}
}
}
Clr\Categorymassaction\Model\Observer
class Clr_Categorymassaction_Model_Observer {
public function addCategoryMassAction(Varien_Event_Observer $observer)
{
$block = $observer ->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Grid) {
$block->getMassactionBlock()->addItem('Clr_Categorymassaction', array(
'label' => Mage::helper('catalog')->__('Add to Category'),
'url' => $block->getUrl('*/*/massCategory', array('_current' => true)),
'additional'=> array(
'visibility' => array(
'name' =>'Category',
'class' =>'required-entry',
'label' =>Mage::helper('catalog')->__('Categories'),
'type' => 'select',
'values' => Mage::getModel('Categorymassaction/system_config_source_category')->toOptionArray(),
'renderer' => 'Categorymassaction/catalog_product_grid_render_category',
)
)
));
};
}
}
One last thing
class Clr_Categorymassaction_Model_System_Config_Source_Category
{
public function toOptionArray($addEmpty = true)
{
$options = array();
foreach ($this->load_tree() as $category) {
$options[$category['value']] = $category['label'];
}
return $options;
}
I am mostly in trouble here because I am refactoring, Flagbit_changeattributeset and Vuleticd_AdminGridCategoryFilter. I know what I need to do (at least I think I do) I just don't know how to finish this off. Thanks for your eyes and ears if you read it all.
UPDATE: The observer from Vuleticd_AdminGridCategoryFilter had this additional code
'filter_condition_callback' => array($this, 'filterCallback'),
)
)
));
};
}
public function filterCallback($collection, $column)
{
$value = $column->getFilter()->getValue();
$_category = Mage::getModel('catalog/category')->load($value);
$collection->addCategoryFilter($_category);
return $collection;
}
This was used to apply the filter to the grid. What I am trying to do is instead of using the dropdown to filter column fields; use the dropdown to trigger the ProductController to pass the selected items a new categoryid.
https://magento.stackexchange.com/questions/67234/productcontroller-for-mass-action Asked this question over at magento's stackexchange figured I would post the link here for posterity.
I am using a Remember Me Component. Actually, migrating a CakePHP 1.3 app to CakePHP 2x. I am stuck with this LAST PIECE of code that is RememberMeComponent.
The script which I see here to SET the cookie is :
function make( ) {
$data = array(
$this->ident_field => $this->_create_token( ),
$this->token_field => $this->_create_token( ),
);
$this->Cookie->name = $this->cookie_name;
$this->Cookie->time = $this->period;
$this->Cookie->key = base64url_encode(implode('::', $data));
$this->Cookie->secure = true;
$this->Auth->getModel()->save(array($this->Auth->userModel => array_merge(array('id' => $this->Auth->user('id')), $data)), false);
}
and checks with :
function check( ) {
$cookie = $this->Cookie->read($this->cookie_name);
if (empty($cookie)) {
return false;
}
$data = explode('::', base64url_decode($cookie));
$user = $this->Auth->getModel( )->find('first', array(
'conditions' => array(
$this->Auth->userModel.'.ident' => $data[0],
),
));
if ( ! $user) {
return false;
}
function base64url_encode is defined in bootstrap - so, it is valid function.
Now there is line:
$this->Auth->getModel()->save(array($this->Auth->userModel => array_merge(array('id' => $this->Auth->user('id')), $data)), false);
That is giving me an error:
Error: Call to undefined method AuthComponent::getModel()
File: /var/www/FlintStones/Controller/Component/RememberMeComponent.php
I checked Auth Component documentation but, it did not have any option where I could find the model for auth.
Thanks in advance.
PS: We cannot directly move to Auto Login (as you might have that in mind) or if you can also refer to a quick-step-by-step, please share. I might even consider that but, so far it is just to get the Auth model.
I had the same issue in the same component.
How to get $settings data out of CakePHP 2.0 FormAuthenticate object
Summary:
Use $this->Auth->userModel to get the model. If the value is null, it will default to 'User'.