I have this example:
$route = new Zend_Controller_Router_Route_Regex(
'blog/archive/(\d+)-(.+)\.html',
array(
'controller' => 'blog',
'action' => 'view'
),
array(
1 => 'id',
2 => 'description'
),
'blog/archive/%d-%s.html'
);
$router->addRoute('blogArchive', $route);
Can anyone tell me what /%d , %s means ?
For example if a have a code like this:
$route = new Zend_Controller_Router_Route_Regex("^([a-z,0-9,-]*)(/|)([a-z,0-9,-]*)(/|)([a-z,0-9,-]*)(/|)([a-z,0-9,-]*)(/|)([a-z,0-9,-]*)(/date/|)([a-z]*)(/page/|)([0-9]*)$",
array(
"module" => "default",
"controller" => "categories",
"action" => "index"
),
array(
1 => 'firstparam',
3 => 'secondparam',
5 => 'theeparam',
7 => 'fourparam',
9 => 'fiveparam',
11 => 'date',
13 => 'page',
)
);
how can i write the last parameter ( 'blog/archive/%d-%s.html') linke in the example. Thank you!
%d means digit and %s means string.
[a-z,0-9,-]* is a regex. Read up more here.
Related
I'm new to contao . I created a backend custom module . The listing of records is looking fine.But When I trying to delete or copy the record the system returns internal server error.And also can't edit pre-saved records.Screenshots are attached below.Please help me.
// List
'list' => array
(
'sorting' => array
(
'mode' => 1,
'fields' => array('title'),
'flag' => 1,
'panelLayout' => 'filter;search,limit'
),
'label' => array
(
'fields' => array('title', 'teaser'),
'format' => '%s <span style="color:#b3b3b3;padding-left:3px;">[%s]</span>'
),
'global_operations' => array
(
'all' => array
(
'label' => &$GLOBALS['TL_LANG']['MSC']['all'],
'href' => 'act=select',
'class' => 'header_edit_all',
'attributes' => 'onclick="Backend.getScrollOffset()" accesskey="e"'
)
),
'operations' => array
(
'editheader' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_solutions']['editheader'],
'href' => 'act=edit',
'icon' => 'edit.gif'
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_solutions']['copy'],
'href' => 'act=copy',
'icon' => 'copy.gif'
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_solutions']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_solutions']['show'],
'href' => 'act=show',
'icon' => 'show.gif'
)
)
),
I have a function to reset a password.
At the point where I have to compare the password and the password_confirm field, I get a strange behavior:
My form
echo $this->Form->hidden('tkn', array('value' => $tkn));
echo $this->Form->hidden('uid', array('value' => $uid));
echo $this->Form->input('password',array('type' => 'password', 'name' => 'data[Appuser][password]'));
echo $this->Form->input('password_confirm',array('type' => 'password', 'name' => 'data[Appuser][password_confirm]'));
My model validation:
var $validate = array(
'password' => array(
'rule' => array('minLength', '6'),
'message' => '{password} minLength 6!'
),
'password_confirm' => array(
'rule' => array('equaltofield','password'),
'message' => '{password_confirm} not equal!'
),
);
function equaltofield($val1, $val2){
return $this->data[$this->alias][key($val1)] == $this->data[$this->alias][$val2];
}
My Controller:
if($this->Appuser->save($this->data)){
$this->Session->setFlash(__('Password has been updated'));
}else{
debug($this->Appuser->invalidFields());
}
Now:
When I submit an empty form I get the following returned from the invalidFields()
array(
'password' => '*****',
'password_confirm' => array(
(int) 0 => '{password_confirm} not equal!',
(int) 1 => '{password_confirm} not equal!'
)
)
Question 1: Why do I not get the message, that the password has not its minlength?
Question 2: Why do I get the second message twice for comparing the password?
When typing in 2 different password with min length, I get this again:
array(
'password_confirm' => array(
(int) 0 => '{password_confirm} not equal!',
(int) 1 => '{password_confirm} not equal!'
)
)
When debug($this->data) I also get this (if that helps somehow)
array(
'Api' => array(
'tkn' => '6837d241bf1076c3c55a95abbcfafa04dc19a33c',
'uid' => '1'
),
'Appuser' => array(
'password' => '*****',
'password_confirm' => 'asdfgh'
)
)
Any ideas regarding my two questions above?
Thanks in advance!!
Try this
var $validate = array(
'password' => array(
'rule' => array('minLength', '6'),
'message' => '{password} minLength 6!'
),
'password_confirm' => array(
'rule' => 'equaltofield',
'message' => '{password_confirm} not equal!'
),
);
function equaltofield($data){
return $this->data[$this->alias]['password'] == $this->data[$this->alias]['password_confirm'];
}
I am getting strange error. please help
I am creating custom module named "Advinvite"
I have created table : "engine4_advinvite_matchinvites"
I have created DbTable : "Advinvite_Model_DbTable_Matchinvites"
I have created DbTable's Row class model : "Advinvite_Model_Matchinvite" And Primary key in the table is "matchinvite_id"
I have also created Api: "Advinvite_Api_Core"
The main part I have also registered the item in manifest.php file of settings folder of module like :
// Items ---------------------------------------------------------------------
'items' => array(
'advinvite_matchinvite',
)
Now regarding Error :
I am getting error "Unknown Item Type : advinvite_matchinvite" when i want to use
Engine:Api:_()->getItem('advinvite_matchinvite',its_Identity)
I am sending the manifest file code too below. please can you check it for me and help me. It has been come in my life first time (weird error) and i am trying to solve this for last three/four days. Even Everything i did correctly why it is happening Not understanding. Please help me mate. It will be very appreciated.
And also if you can help me with this too means Routes are also not working....Don't know why these both errors are coming
Help Me Please.
Manifest.php Code:
<?php return array (
'package' =>
array (
'type' => 'module',
'name' => 'advinvite',
'version' => '4.0.0',
'path' => 'application/modules/Advinvite',
'title' => 'Advanced Invites',
'description' => 'This will invite the users for matches and nets',
'author' => 'Gitesh Dang',
'callback' =>
array (
'class' => 'Engine_Package_Installer_Module',
),
'actions' =>
array (
0 => 'install',
1 => 'upgrade',
2 => 'refresh',
3 => 'enable',
4 => 'disable',
),
'directories' =>
array (
0 => 'application/modules/Advinvite',
),
'files' =>
array (
0 => 'application/languages/en/advinvite.csv',
),
// Items ---------------------------------------------------------------------
'items' => array(
'advinvite_matchinvite',
),
// Routes --------------------------------------------------------------------
'routes' => array(
'advinvite_general' => array(
'route' => 'invites/:action/*',
'defaults' => array(
'module' => 'advinvite',
'controller' => 'index',
'action' => '(match|matchview)',
),
'reqs' => array(
'action' => '\D+',
)
),
)
),
); ?>
Waiting for postive response.
Kind regards
Mates,
It has been fixed.
The issue was minor :)
Items was registered in package array and it should be registered outside of package array. Package array should be closed to files array only.
Corrected Manifest File :
<?php return array (
'package' =>
array (
'type' => 'module',
'name' => 'advinvite',
'version' => '4.0.0',
'path' => 'application/modules/Advinvite',
'title' => 'Advanced Invites',
'description' => 'This will invite the users for matches and nets',
'author' => 'Gitesh Dang',
'callback' =>
array (
'class' => 'Engine_Package_Installer_Module',
),
'actions' =>
array (
0 => 'install',
1 => 'upgrade',
2 => 'refresh',
3 => 'enable',
4 => 'disable',
),
'directories' =>
array (
0 => 'application/modules/Advinvite',
),
'files' =>
array (
0 => 'application/languages/en/advinvite.csv',
),
),
// Items ---------------------------------------------------------------------
'items' => array(
'advinvite_matchinvite',
),
// Routes --------------------------------------------------------------------
'routes' => array(
'advinvite_general' => array(
'route' => 'invites/:action/*',
'defaults' => array(
'module' => 'advinvite',
'controller' => 'index',
'action' => '(match|matchview)',
),
'reqs' => array(
'action' => '\D+',
)
),
)
); ?>
Cheers !! :)
I've successfully created my Route using Regex. I have Several Optional Parameters in my route that I don't want displayed in the URL Helper unless the user has specified them. How can I accomplish this?
This is what I currently have
$route = new Zend_Controller_Router_Route_Regex(
'([a-zA-Z-_0-9-]+)-Widgets(?:/page/(\d+))?(?:/limit/(\d+))',
array(
'controller' => 'widget',
'action' => 'list',
),
array(
1 => 'color',
2 => 'page',
3 => 'limit'
),
'%s-Widgets/'
);
$router->addRoute('color_widgets', $route);
I then call the URL Helper with following code
echo $this->url(array('page' => $page), 'color_widgets', false);
This results in /Blue-Widgets/ and does not send the Page to the URL. I can fix this by changing the reverse in the Router
$route = new Zend_Controller_Router_Route_Regex(
'([a-zA-Z-_0-9-]+)-Widgets(?:/page/(\d+))?(?:/limit/(\d+))',
array(
'controller' => 'widget',
'action' => 'list',
'page' => 1
),
array(
1 => 'color',
2 => 'page',
3 => 'limit'
),
'%s-Widgets/page/%d'
);
However this doesn't solve my problem say I have a Url
/Blue-Widgets/page/1/limit/10 The limit doesn't show, again I can fix that with the following
$route = new Zend_Controller_Router_Route_Regex(
'([a-zA-Z-_0-9-]+)-Widgets(?:/page/(\d+))?(?:/limit/(\d+))',
array(
'controller' => 'widget',
'action' => 'list',
'page' => 1,
'limit' => 10
),
array(
1 => 'color',
2 => 'page',
3 => 'limit'
),
'%s-Widgets/page/%d/limit/%d'
);
The problem with this is the user is at
/Blue-Widgets/ and I want to take them to the next page of Blue Widgets with following code
echo $this->url(array('page' => $page), 'color_widgets', false);
They are actually taken to
/Blue-Widgets/page/2/limit/10
When I actually want to take them to
/Blue-Widgets/page/2
How can I accomplish this with the Zend Framework.
It is not possible to use a regex reverse route with a variable number of values.
You could:
Write a different route for every optional parameter (not recommended)
Use a different route structure
You could, for instance change your route to:
$route = new Zend_Controller_Router_Route(
'widgets/:color/*',
array(
'controller' => 'widget',
'action' => 'list',
'page' => 1,
'limit' => 10
),
array(
'color' => '[a-zA-Z-_0-9-]+',
'page' => '\d+',
'limit' => '\d+',
)
);
Another option would be to create your own custom route class, which can parse and build the correct uri.
You've give wrong Regex match variable indexes, that's why you get weird results. Your code should look like this:
$route = new Zend_Controller_Router_Route_Regex(
'([a-zA-Z-_0-9-]+)-Widgets(?:/page/(\d+))?(?:/limit/(\d+))',
array(
'controller' => 'widget',
'action' => 'list',
),
array(
1 => 'color',
3 => 'page',
5 => 'limit'
),
'%s-Widgets/'
);
$router->addRoute('color_widgets', $route);
How to put space in between option value of Zend_Form_Element_Select
Expected result as follows,
http://jsfiddle.net/HLbQE/
Tried as follows,
$this->addElement('Select', 'parent_id', array(
'label' => 'Select Category',
'multiOptions' => array('0'=>'Gents','1'=>' Jeans','2'=>' Sunglass','3'=>'Ladies','4'=>' Jeans','5'=>' Sunglass')
));
but fails,
Any help please
Why not just use optgroups? ZF handles this natively by using a nested array for the multi-options, eg
$options = array(
'Gents' => array(
1 => 'Jeans',
2 => 'Sunglass'
),
'Ladies' => array(
3 => 'Jeans',
4 => 'Sunglass'
)
);
Updated demo here - http://jsfiddle.net/HLbQE/1/
Try this:
$this->addElement('Select', 'parent_id', array(
'label' => 'Select Category',
'multiOptions' => array('0'=>'Gents','1'=>' Jeans','2'=>' Sunglass','3'=>'Ladies','4'=>' Jeans','5'=>' Sunglass'),
'escape' => false // <-- added
));
I seems this will not work indeed, as reported in this, still unresolved, issue:
http://framework.zend.com/issues/browse/ZF-5351