Adding Vendor Specific Module To Zend Framework 2.0 - propel

I have looked at some of the previous Stack posts out there on how to load a vendor library in ZF2, but I think they are a bit dated. I am trying to figure out how to add my vendor library "Propel" correctly.
I get an error from Zend Framework Saying "Unable to load 'Propel' Module"
Here is my setup.
In my application.config.php
return array(
'modules' => array(
'Application',
'Propel' // Module I am trying to add
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
Here is the setup of my vendor directory
-Vendor
-Propel
-runtime
-config
-autoload_classmap.php
-Module.php
Here is my Module.php
namespace ORM;
class Module
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
)
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
Here is my autoload_classmap.php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'Propel' => __DIR__ . '/runtime/lib/Propel.php'
);
Any ideas?

The namespace name must be "Propel". The folder name, module namespace name, and module name in the application.config.php must be EXACTLY the same.

Related

How to upgrade multiple file of database in magento 2

I am not able to update upgrade schema file.
I want to update database using upgrade schema file that i have already updated.
In my module i have a database table which is created using install schema file.
This is my UpgradeSchema file
<?php
namespace Mageplaza\HelloWorld\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '1.2.0', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable( 'mageplaza_helloworld_post' ),
'test',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
'nullable' => true,
'length' => '12,4',
'comment' => 'test',
'after' => 'status'
]
);
}
$installer->endSetup();
}
}
this file is correctly updated
now i want also update my table with new column like this
<?php
namespace Mageplaza\HelloWorld\Setup;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
$installer = $setup;
$installer->startSetup();
if(version_compare($context->getVersion(), '1.2.0', '<')) {
$installer->getConnection()->addColumn(
$installer->getTable( 'mageplaza_helloworld_post' ),
'test123',
[
'type123' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
'nullable' => true,
'length' => '12,4',
'comment' => 'test123',
'after' => 'status'
]
);
}
$installer->endSetup();
}
}
This is not work properly
Seems that you have a mistake in the addColumn() definitions.
You should use 'type' instead of 'type123'.

Add mailto functionality in admin field

How can i new field in admin filed that contain mailto functionality
$fieldset->addField('email', 'link', array(
'label' => Mage::helper('mumodule')->__('Email'),
"target"=>"_blank",
'mailto' => Mage::registry('mumodule')->getData('email'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));
using this way i cant add functionality.
is it possible to add new filed with mailto functionality?
You must create your own form field renderer. For this you will need a custom module. If you don't know how to do that here's a good starting point: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_create_an_admin_form_module
Create a new file in app/code/[local/community]/MyCompany/MyModule/Varien/Data/Form/Element/Mailto.php with this content:
class MyCompany_MyModule_Varien_Data_Form_Element_Mailto extends Varien_Data_Form_Element_Abstract {
public function __construct($data) {
parent::__construct($data);
$this->setType('link');
}
public function getElementHtml() {
$html = $this->getBeforeElementHtml();
if ($this->getValue()) {
$html .= ' ';
}
$html .= $this->getAfterElementHtml();
return $html;
}
After that go to your form file and add this to the fieldset:
$fieldset->addType('mailto','MyCompany_MyModule_Varien_Data_Form_Element_Mailto');
$fieldset->addField('email', 'mailto', array(
'label' => Mage::helper('mymodule')->__('Email'),
'name' => 'email',
));
Of course, you should replace MyCompany namespace with the namespace that you already use in the module and MyModule with your module name. Also don't forget to place the file in the code pool where your module already exists: local/community
i achieve in simple way
$fieldset->addField('email', 'link', array(
'label' => Mage::helper('mumodule')->__('Email'),
'target' => '_blank',
'href' => 'mailto:' . urlencode(Mage::registry('mumodule')->getData('email')),
'class' => 'required-entry',
));
mailto: is part of the URL so it should be assigned in the href attribute:

Zend Framework 2 Album Tutorial 404 error occurred The requested URL could not be matched by routing MAMP OSX

just posted this on IRC channel ZFTalk too,
Hope I can get some help on ZF2, ZF2 Album Tutorial, OSX using MAMP. Skeleton framework, homepage is working.
Issue : After completing section : 8.5 Listing albums, you fill up the module/Album/view/album/album/index.phtml with some code, then they ask you to preview the page on http://zf2-tutorial.localhost/album.
I get a 404, The requested URL could not be matched by routing.
I headed to Google for advice. Found a GIT repository with a 'fully working model' of the Tutorial, so i got this to compare my code with. If i set up this as another host I get the same 404 routing message.
After carefully studying the manual, it explicitly states in the start that you will not be able to view anything other than the start/home page if your httpd.conf / AllowOverride is not set to FileInfo.
Decided to scan the whole machine for files called httpd.conf, just for in case the path to the one I changed is not used by MAMP when powering up the server.
So found 3, changed all of them (Although 3 we're found, I believe the correct route is /private/etc) My problem still exists in the code i wrote from the tutorial, as well as the GIT code of the 'working model'.
Has anyone encountered issues with this? found this on stackoverflow Zend Framework 2 .htaccess mamp pro which has similarities to my problem but has not resolved it. Can anyone in here help me?
Other routes taken involve : Checking for spelling mistakes in the code, checking the application.config.php has a route set up. Please advise? :)
Module.php
<?php
namespace Album;
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
class Module
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'factories' => array(
'Album\Model\AlbumTable' => function($sm) {
$tableGateway = $sm->get('AlbumTableGateway');
$table = new AlbumTable($tableGateway);
return $table;
},
'AlbumTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
}
module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
),
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);
Resolved this error with help from this thread.
I think, barring any other misconfiguration, the source of this error - for me at least - was where to register the Album module.
The SKELETON Application comes with an Application MODULE. Those are two different things and they have have their own config folders:
config // SKELETON Application config
module/Application/config // Application MODULE config
The module needs to be registered in the Skeleton Application config file provided with the skeleton, namely config/application.config.php and NOT by creating an application.config.php file in the Application Module config, e.g. module/Application/config/application.config.php.
You can solve is by configuring the apache settings in (httpd.conf) change the
"AllowOverride None" to "AllowOverride All".
Such setting permit you to override the config value by .htaccess
Please try this
If you see a standard Apache 404 error, then you need to fix .htaccess usage before continuing. If you’re are using IIS with the URL Rewrite Module, import the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ index.php [NC,L]
You now have a working skeleton application and we can start adding the specifics for our application. Please let me know if it worked fine from you.

ZF2: How do I implement a custom filter?

I've been working with Zend Framework 2 for a few weeks now, and, even though the documentation online is pretty incomplete, I managed to build up a first draft of my website.
Unfortunately, I got stuck while trying to implement a custom version of the Zend\Filter\File\Rename filter; here I sum up what I've done:
1) In my module called 'Library', created the file
src\Library\Filter\File\Rename.php
namespace Library\Filter\File;
use Traversable;
use Zend\Filter;
use Zend\Filter\Exception;
use Zend\Stdlib\ArrayUtils;
class Rename extends Filter\AbstractFilter {
static $uploadDir = '/srv/default/htdocs/public/uploads/';
public function filter($value) {
do {
$newname = md5(uniqid(time()));
} while(file_exists(self::uploadDir . $newname);
if (rename($value, self::uploadDir . $newname) !== true)
throw new Exception\RuntimeException(sprintf("File '%s' could not be renamed. An error occurred while processing the file.", $value));
return self::uploadDir . $newname;
}
}
As you can see, is pretty simple. Here's the module config:
module.config.php
<?php
return array(
'controllers' => array(
// Invokables don't support dependencies
'invokables' => array(
'myFileRename' => 'Library\Filter\File\Rename',
),
));
While the form is:
[...]
public function getInputFilterSpecification() {
return array(
'file' => array(
'required' => false,
'filters' => array(
// Custom Renamer
array('name' => 'myFileRename'),
),
)
);
}
}
?>
But this is not working, as I always get an exception:
Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for myFileRename' in /srv/default/vendor/ZF2/library/Zend/ServiceManager/ServiceManager.php:420
Stack trace:
#0 /srv/default/vendor/ZF2/library/Zend/ServiceManager/AbstractPluginManager.php(108): Zend\ServiceManager\ServiceManager->get('myfilerename', true)
#1 /srv/default/vendor/ZF2/library/Zend/Filter/FilterChain.php(179): Zend\ServiceManager\AbstractPluginManager->get('myfilerename', NULL)
#2 /srv/default/vendor/ZF2/library/Zend/InputFilter/Factory.php(263): Zend\Filter\FilterChain->attachByName('myfilerename', Array)
#3 /srv/default/vendor/ZF2/library/Zend/InputFilter/Factory.php(171): Zend\InputFilter\Factory->populateFilters(Object(Zend\Filter\FilterChain), Array)
#4 /srv/default/vendor/ZF2/library/Zend/InputFilter/Factory.php(237): Zend\InputFilter\Factory->createInput(Array)
#5 /srv/default/vendor/ZF2/library/Zend/Form/Form.php(672) in /srv/default/vendor/ZF2/library/Zend/ServiceManager/ServiceManager.php on line 420
Unfortunately I found no article on the entire internet to help me with this, and I still get this error even when aliasing my filter as a factory :/ What do I have to do?
You load the filter as if it is a controller (hence, the controller key in your module config). The filter has a plugin manager, but for this filter you do not need the plugin manager. There is also no link in the filter plugin manager with the MVC configuration.
The most simple way is to just instantiate the filter yourself. It should be something like this that would work:
use Library\Filter\File\Rename as RenameFilter;
public function getInputFilterSpecification()
{
return array(
'file' => array(
'required' => false,
'filters' => array(
new RenameFilter,
),
)
);
}
just use:
'name' => 'file',
'required' => false,
'filters' => array(
array('name' => 'Library\Filter\File\Rename'),
),
had the same problem... this was the solution for me...

CodeIgniter form validation multilanguage labels

I'm currently working on a website that can be viewed in 3 different languages. I've put all text into languages files and almost everything is working as expected.
Things like configuration for pagination I've put into a configuration file and into application/config, like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['num_links'] = 2;
$config['full_tag_open'] = '<p class="pagination">';
$config['full_tag_close'] = '</p>';
$config['first_link'] = '« ' . lang('first');
$config['last_link'] = lang('last') . ' »';
And it works great, but I've tried the same for my form validation configuration file, like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'login' => array(
array(
'field' => 'login_email',
'label' => lang('emailaddress'),
'rules' => 'trim|required|valid_email|min_length[6]'
),
array(
'field' => 'login_password',
'label' => lang('password'),
'rules' => 'trim|required'
),
),
But this doesn't seem to work. It looks like this configuration file gets loaded before the language files/library.
And to be honest, at the moment I don't really have an idea how to fix this other than taking everything out of the configuration file again, and put it into the controller, but I'd rather not do this.
Any ideas how to fix this?
if you check how field translation is done when defining form validation rules (see example below and consider the second argument):
$this->form_validation->set_rules('first_name', 'lang:first_name', 'required');
you can see where you are doing wrong in your actual code.
instead of:
array(
'field' => 'login_password',
'label' => lang('password'),
'rules' => 'trim|required'
),
the way to go is:
array(
'field' => 'login_password',
'label' => 'lang:password',
'rules' => 'trim|required'
),
#Krishna Raj K
i use a trans function like you. And i have fixed it.
one more thing that i use wiredesignz hmvc.
MY_Form_validation.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/** application/libraries/MY_Form_validation **/
class MY_Form_validation extends CI_Form_validation
{
public $CI;
protected function _translate_fieldname($fieldname)
{
// Do we need to translate the field name? We look for the prefix 'trans:' to determine this
if (sscanf($fieldname, 'trans:%s', $line) === 1 )
{
return trans($line);
}
return $fieldname;
}
}
rules in model
'parent_id' => array(
'field'=>'parent_id',
'label'=>'trans:main.taxonomy.column.parent_id.name',
'rules'=>'is_natural_no_zero',
),
and in controller, you must load according to this order
//helper
$this->load->helper(array('array','form','anhtocon','trans'));
//library
$this->load->library(array('Nested_set','form_validation'));
$this->form_validation->CI =& $this;
//model
$this->load->model('taxonomy_model');

Resources