I want to modify the validation related email address in Zend Framework. But I'm confused with how to find the page related to validation in this. Actually it was already written and I need to modify its rule.
I tried to search all the pages in the project to find where this validation is defined and the PHP namespace is referenced to this – I’m at my wits’ end!”
Only thing that I could found is below commands.
1,use Zend\Validator;
2,$userEmailInput->getValidatorChain()->addValidator(new Validator\EmailAddress());
Could anyone please help me to find this treasure where it is located normally. Give some hints for finding this and for modifying the rules.
Thanks in advance
The file is located in folder vendor/zendframework/zend-validator/src/EmailAddress.php, as stated by the namespace.. You can even find it on github
However, I discourage you to modify that specific file. On the first update, all your edits will be wiped out.
The right solution would be to create a new custom validator:
namespace YourNamespace\Validator;
use Zend\Validator\EmailAddress;
class YourEmailAddress extends EmailAddress
{
public function isValid($value)
{
// Your validation logic..
}
}
Then, where you need it:
$userEmailInput->getValidatorChain()->addValidator(new YourNamespace\Validator\YourEmailAddress());
Related
I'm new to ATK4.
I'm trying to implement an Autocomplete field, but I had only an error when I try to define the field.
I'm running all on a MAC with the last version (4.2.4) of ATK4. All other functions (field types) seems to work well, but when I define a field of type autocomplete I get the same error I saw on the example: http://codepad.agiletoolkit.org/autocomplete
The case is I defined a model:
class Model_Agenda extends Model_Table {
public $entity_code='Agenda';
function init(){
parent::init();
$this->addField('DATE');
$this->addField('TIME');
$this->addField('DRIVERID');
$this->addField('STUDENTID');
$this->hasOne('STUDENTID')->display(array('form'=>'autocomplete/Basic'));
}
}
and then on my Page:
$form = $this->add('Form');
$form->addField('ReadOnly','Date')->Set($_GET['date']);
$form->addField('ReadOnly','Time')->Set($_GET['time']);
$form->addField('ReadOnly','Driver')->Set($_GET['driverid']);
$client=$form->addField('autocomplete','studentid');
something simple, but nothing, I cannot get the autocomplete field, I ever get an error that say that "autocomplete.php" doesn't exist (actually the file doesn't exist and I try to download the github module, but either that module includes this file), anyway the error I get is:
Exception_PathFinder, code: 0
Additional information:
file: Form/Field/Autocomplete.php
type: php
attempted_locations:
0: /Library/WebServer/Documents/rutas/lib/Form/Field/Autocomplete.php
1: /Library/WebServer/Documents/rutas/atk4/lib/Form/Field/Autocomplete.php
2: /Library/WebServer/Documents/rutas/atk4-addons/mvc/Form/Field/Autocomplete.php
3: /Library/WebServer/Documents/rutas/atk4-addons/misc/lib/Form/Field/Autocomplete.php
class: Form_Field_Autocomplete
namespace:
orig_class: Form_Field_Autocomplete
/Library/WebServer/Documents/rutas/atk4/lib/PathFinder.php:207
Someone could help me please?
You're talking about this add-on, right: https://github.com/atk4/autocomplete?
Looks like issue with PathFinder unable to find appropriate location of namespaced addons.
Please post here part of your API_Frontend class where you add additional locations to pathfinder and also tell me something more about your folder structure (in which folder you have put autocomplete add-on files).
ATK 4.2.4 version is not last. Can you try to upgrade ATK to version 4.2.5? It's not officially released, but is available in GitHub master branch here: https://github.com/atk4/atk4?
I hope everything will work with 4.2.5 version but if not, then I'll help you solve this issue.
And one more thing - if you're creating form fields manually, then you need to set Model for that $client field. I guess it can be done with $client->setModel('Agenda');
EDIT: correct answer
In line
$client=$form->addField('autocomplete','studentid');
you should write full autocomplete field class name with namespace like this:
$client=$form->addField('autocomplete/Basic', 'studentid');
One more thing to note is to use lowercase function name. So instead of Set() use set().
I am using codeigniter for a project that is used by a variety of companies.
The default version of our software is up and running and works fine - however some of our customers want slightly different view files for their instance of the system.
Ideally what I would like to do is set a variable (for example VIEW_SUFFIX) and whenever a view file is loaded it would first check if there was a suffix version available if there was use that instead.
For example if the system had a standard view file called 'my_view.php' but one client had a VIEW_SUFFIX of 'client_1' - whenever I called $this->load->view('my_view') if the VIEW_SUFFIX was set it would first check if my_view_client_1 existed (and if it did use that) or if not use the default my_view.php.
I hope that my question is clear enough... If anyone has done this before or can think of a way to do it I would really appreciate it.
EDIT:
Ideally I would like a solution that works without me changing every place that I am calling the view files. Firstly because there are a few files that may want different client versions and also because the view files are called from a lot of controllers
I had a similar requirement for which I created a helper function. Among other things, this function can check for a suffix before loading the specified view file. This function can check for the suffix and check if the file exists before loading it.
Unfortunately, the file checking logic would be a bit brittle. As an alternative, you can implement a MY_Loader class that will override the basic CI_Loader class.
Something like this in your application/core/MY_Loader.php:
class MY_Loader extends CI_Loader {
protected function _ci_load($_ci_data)
{
// Copy paste code from CI with your modifications to check prefix.
}
}
Could you not do this
// some method of creating $client
// probably created at login
$_SESSION['client'] = 'client_1';
$client = (isset($_SESSION['client'])) ? $_SESSION['client'] : '';
$this->load->view("your_view{$client}", $data);
I want to override the guestbook functionality. To be exact, I want to override the action_form_save_entry() function on [mysite]/concrete5/core/controllers/blocks/guestbook.php
I've tried to override it these ways:
[mysite]/controllers/blocks/guestbook.php
[mysite]/core/controllers/blocks/guestbook.php
noe of them works. I can't find any way how to override that file. The documentation here and here doesn't show how to override that /core/ directory. Their forum never helps. Google result also just get misled with the 'core' keyword. All the result just take the 'core' meaning as just what's exist on the /concrete5/ directory, not the exact true /concrete5/core
Looks like that /concrete5/core/ directory appear only on the newer version. CMIIW.
Btw, maybe I should also tell you what I want to do with that function. Probably you have another workaround for this instead of simply overriding it. I want to add SMS notification functionality to it. So whenever someone submit a new comment, an SMS would be sent to the admin of a particular page.
Yes, the /concrete/core directory structure is new to 5.6. Tutorials and documentation on c5 can be ... lacking ... but in this case it's just a matter of them being behind a bit.
The "real" guestbook controller is at /concrete/blocks/guestbook/controller.php. You'll notice that it's just a shell of a class:
class GuestbookBlockController extends Concrete5_Controller_Block_Guestbook {}
The file that you referenced defines Concrete5_Controller_Block_Guestbook.
So, the solution is to override the real controller, not whatever it extends (ie, the file that you were looking at). Thinking in this way, it should be clearer that you need to create a file at /blocks/guestbook/controller.php. In fact, just copy the controller.php that I referenced above because you need to keep the (sometimes multiple) classes. Then, you can override the particular function. (Don't forget to call parent::action_save_form_entry()).
I'm trying to create a widget within the module and then load that widget from 'outside' of the module. More particularly I'm using user module written by someone else. I don't want to have a separate page for displaying a login form, therefore I tried to make a CPortlet/widget (confusion) displaying the login form. Basically, I've moved the code from LoginController into that widget. Then I try to display the widget on some random page by
<?php $this->widget('user.components.LoginForm'); ?>
However, I get an error
CWebApplication does not have a method named "encrypting".
in UserIdentity class in this line:
else if(Yii::app()->controller->module->encrypting($this->password)!==$user->password)
This happens, because I'm basically trying to execute this code within context of the app and not the module. Thus the "Yii::app()->controller->module" trick doesn't really work as expected.
What am I doing wrong:-\
Is there a better way to achieve this. I.e. display that login form in some other page, which is normally displayed by accessing login controller within user module (user/login) or is a widget the right way of doing it?
Thanks.
The quick solution
Ok, so I simply ended up doing
Yii::app()->getModule('user')->encrypting($this->password)
instead of
Yii::app()->controller->module->encrypting($this->password)
Notice that now the module must be called 'user' in the main config, but I think this allows for more flexibility. I.e. we're not bound to only use module functionality within the module.
Additional insight on displaying widget outside of the module scope
After playing more with it that's what I did. In the UserModule.php I've created a method
public static function id() {
return 'user';
}
Then everywhere where I need the module I use
Yii::app()->getModule(UserModule::id())->encrypting($this->password)
I don't like having many imports related to the module like:
'application.modules.user.models.*',
'application.modules.user.components.*',
Because we already have those imports in the UserModule.php:
public function init()
{
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'user.models.*',
'user.components.*',
));
}
Therefore whenever you know that some piece of functionality will be used outside of the module it's important to make sure the module is loaded. For example, in the LoginForm widget that I am trying to display NOT in one of the module controllers, I have this line of code:
$model = new UserLogin;
However, UserLogin is a model inside of the User module, and in order to be able to autoload this model we first have to make sure the module was initialised:
$module = Yii::app()->getModule(UserModule::id());
$model = new UserLogin;
I hope this will be helpful if you were stuck with the whole modules concept the way I was.
http://www.yiiframework.com/forum/index.php?/topic/6449-access-another-modules-model/ was useful but hard to find =)
You better move that encrypting() into a MyUserIdentiy class which extends CUserIdentity. Whatever the code you take to use, they putting the method in controller is a bad idea and as a result you cannot reuse that code.
The login form should still post to User/Login controller but I guess they use Yii's standard login code and you might want to modify it to use the MyUserIdentity.
In cake 1.2 there is a feature that allows the developer to no have to create models, but rather have cake do the detective work at run time and create the model for you. This process happens each time and is neat but in my case very hazardous. I read about this somewhere and now I'm experiencing the bad side of this.
I've created a plugin with all the files and everything appeared to be just great. That is until i tried to use some of the model's associations and functions. Then cake claims that this model i've created doesn't exist. I've narrowed it down to cake using this auto model feature instead of throwing and error! So i have no idea what's wrong!
Does anybody know how to disable this auto model feature? It's a good thought, but I can't seem to find where i've gone wrong with my plugin and an error would be very helpful!
There's always the possibility to actually create the model file and set var $useTable = false.
If this is not what you're asking for and the model and its associations actually do exist, but Cake seems to be unable to find them, you'll have to triple check the names of all models and their class names in both the actual model definition and in the association definitions.
AFAIK you can't disable the auto modelling.
Cake 1.2
It's a hack and it's ugly cus you need to edit core cake files but this is how i do it:
\cake\libs\class_registry.php : line 127ish
if (App::import($type, $plugin . $class)) {
${$class} =& new $class($options);
} elseif ($type === 'Model') {
/* Print out whatever debug info we have then exit */
pr($objects);
die("unable to find class $type, $plugin$class");
/* We don't want to base this on the app model */
${$class} =& new AppModel($options);
}
Cake 2
Costa recommends changing $strict to true in the init function on line 95 of Cake\Utility\ClassRegistry.php
See Cake Api Docs for init
ClassRegistry.php - init function
Use
var $useTable = false;
in your model definition.
Delete all cached files (all files under app/tmp, keep the folders)
In most cases where models seem to be acting in unexpected ways, often they dont include changes you've made, it is because that cake is useing an old cached version of the model.
Uh...where do we start. First, as Alexander suggested, clear your app cache.
If you still get the same behaviour, there is probably something wrong with the class and/or file names.
Remember the rules, for controller:
* classname: BlastsController
* filename: blasts_controller.php
for model:
* classname: Blast
* filename: blast.php
Don't foget to handle the irregular inflections properly.