I am using drupal 6. I have a node called [classroom]. I would like to have a [vacancy register] associated with each classroom.
vacancy register is a cck type with:
- uid
- nid
- join date
I would like for each user to [register] for a vacancy. I think I can use flag for this.
When a user joins, I can use rules to action an email to be sent to the user and the [classroom]->cck_email field.
I would like a rule schedule to also run every 30 days ( configurable ) to alert the user to confirm their [registration].
1a. If no registration is confirmed, then 14 days later, the user is [unregistered] from the classroom.
1b. If user confirms registration ( by clicking on a button or url ). then the rule 1 runs again.
I would like to confirms if my approach to this is correct.
Update:
I have been playing around with signup, but there are the rules schedule aspect of it that I find hard customising to my liking.
I'm trying to write a rules event for signup_signup and signup_cancel, then action it through rules schedule. But there a bit of existing signup code I have to look through.
Have to do too much custom work to signup, so I thought, its easier to just do it with rules and flags. The downside is having to also create the UI for it.
For the signup module,
I have the following rules event.
Could this be reviewed please?
<http://drupal.org/node/298549>
function signup_rules_event_info() {
return array(
'signup_signup' => array(
'label' => t('User signups to classroom'),
'module' => 'Signup',
'arguments' => array(
'userA' => array('type' => 'user', 'label' => t('UserA, which adds userB.')),
'userB' => array('type' => 'user', 'label' => t('UserB, which is added to UserA\'s list.')),
),
),
);
}
I don't know what to do with the arguments list.
I haven't looked at the signup module for some time, but I think that might be a better module for your case. The flag module is a good choice too, but the signup module is more geared towards what you are doing. Users signing up for content like a classroom.
Related
My accurate question would be, is there any routes that can make possible that when i go
mydomain.com/profilename
it'd be redirect to the profile controllers instead of index, and sitll, if i provide no parameter, he'd load the index page, and even still, if theres a controller by that name, that he'd run that controller instead of searching for a profile...
Pretty much complicated i know, that's why i'm asking for your help, you geniouses! <3
Thanks in advance, Jorge.
ZF1 doesn't have route priority as such, but routes are matched LIFO (last in, first out). So as long as you were able to hard code controller names into your routes, and put this after your profile route, you could do something like this:
$router->addRoute('profile',
new Zend_Controller_Router_Route('/:profilename', array(
'module' => 'default',
'controller' => 'profile',
'action' => 'view'
))
);
$router->addRoute('something',
new Zend_Controller_Router_Route('/:controller/:action', array(
'module' => 'default',
'action' => 'index'
), array(
'controller' => '(foo|bar)' // names of your controllers
))
);
Alternatively, if this isn't possible, or you want a more robust (but more difficult) solution, I wrote a blog post a while back with a detailed explanation of how to achieve this with a custom route class: http://tfountain.co.uk/blog/2010/9/9/vanity-urls-zend-framework
I'm using cakePhp to create a Rest api (see http://book.cakephp.org/2.0/fr/development/rest.html) and I need to get nested resources. The documentation tells how to get let's say books implementing a URI /books.json. But does not tell how to get for example reviews for a given book. What I'm trying to make is somthing like this: /books/14/reviews.json that returns Review resources.
Can any one tell me hwo to make this?
See the Custom REST Routing section of the docs you've linked. In case the default routing doesn't work for you, you'll have to create your own custom routes that either replace or extend the default ones.
Your /books/14/reviews.json URL could for example be mapped to BooksController::reviews() likes this:
Router::connect(
'/books/:id/reviews',
array(
'[method]' => 'GET',
'controller' => 'books',
'action' => 'reviews'
),
array(
'id' => Router::ID . '|' . Router::UUID,
'pass' => array(
'id'
)
)
);
When placed before Router::mapResources() it should work fine together with the default routes.
I'm building my first Zend Framework application and I want to find out the best way to fetch user parameters from the URL.
I have some controllers which have index, add, edit and delete action methods. The index action can take a page parameter and the edit and delete actions can take an id parameter.
Examples
http://example.com/somecontroller/index/page/1
http://example.com/someController/edit/id/1
http://example.com/otherController/delete/id/1
Until now I fetched these parameters in the action methods as so:
class somecontroller extends Zend_Controller_Action
{
public function indexAction()
{
$page = $this->getRequest->getParam('page');
}
}
However, a colleague told me of a more elegant solution using Zend_Controller_Router_Rewrite as follows:
$router = Zend_Controller_Front::getInstance()->getRouter();
$route = new Zend_Controller_Router_Route(
'somecontroller/index/:page',
array(
'controller' => 'somecontroller',
'action' => 'index'
),
array(
'page' => '\d+'
)
);
$router->addRoute($route);
This would mean that for every controller I would need to add at least three routes:
one for the "index" action with a :page parameter
one for the "edit" action with an :id parameter
one for the "delete" action with an :id parameter
See the code below as an example. These are the routes for only 3 basic action methods of one controller, imagine having 10 or more controllers... I can't imagine this to be the best solution. The only benefit that i see is that the parameter keys are named and can therefore be omitted from the URL (somecontroller/index/page/1 becomes somecontroller/index/1)
// Route for somecontroller::indexAction()
$route = new Zend_Controller_Router_Route(
'somecontroller/index/:page',
array(
'controller' => 'somecontroller',
'action' => 'index'
),
array(
'page' => '\d+'
)
);
$router->addRoute($route);
// Route for somecontroller::editAction()
$route = new Zend_Controller_Router_Route(
'somecontroller/edit/:id',
array(
'controller' => 'somecontroller',
'action' => 'edit'
),
array(
'id' => '\d+'
)
$router->addRoute($route);
// Route for somecontroller::deleteAction()
$route = new Zend_Controller_Router_Route(
'somecontroller/delete/:id',
array(
'controller' => 'somecontroller',
'action' => 'delete'
),
array(
'id' => '\d+'
)
$router->addRoute($route);
I tend to look at it this way:
Determine processing requirements.
What does each "action" need? An edit action and a delete action probably require an :id param. An add action and a list action probably do not. These controllers/actions then consume the params and do the processing.
Note: You can write these comtrollers/actions without any reference to the urls that bring visitors there. The actions simply expect that their params will be delivered to them.
Decide (!) what url's you want.
In general, I find the the (/:module/):controller/:action part of the url largely works fine (except for top-level relatively-static pages like /about, where I often put the actions on an IndexController (or a StaticController) and resent having to include the /index prefix in the url.
So, to handle posts, you might want urls like:
/post - list all posts, probably with some paging
/post/:id - display a specific post
/post/:id/edit - edit a specific post
/post/:id/delete - delete a specific post
/post/add - add a post
Alternatively, you might want:
/post/list - list all posts, probably with some paging
/post/display/:id - display a specific post
/post/edit/:id - edit a specific post
/post/delete/:id - delete a specific post
/post/add - add a post
Or any other url scheme. The point is, you decide the url's you want to expose.
Create routes...
...that map those urls to controllers/actions. [And make sure that whenever you render them, you use the url() view-helper with the route-name, so that a routing change requires no changes to your downstream code in your actions or views.
Do you end up writing more routes this way? Yeah, I find that I do. But, for me, the benefit is that I get to decide on my urls. I'm not stuck with the Zend defaults.
But, as with most things, YMMV.
It all depends on your exact requirements. If you simply want to pass one or two params, the first method will be the easiest. It is not practical to define route for every action. A few scenarios where you would want to define routes would be:
Long urls - If the parameter list for a particular action is very long, you might want to define a route so that you can omit the keys from the request and hence shorten the url.
Fancy urls - If you want to deviate from the normal controller/action url pattern of the Zend Framework, and define a different url pattern for your application (eg, ends with ".html")
Slugs / SEO friendly URLs
To take the example of a blog, you might want to define routes for blog posts urls so that the url is SEO friendly. At the same time, you may want to retain the edit / delete / post comment etc urls to remain the ZF default and use $this->getRequest->getParam() to access the request parameters in that context.
To sum up, an elegant solution will be a combination of routes and the default url patterns.
In a previous answer #janenz00 mentioned "long urls" as one of the reasons for using routes:
Long urls - If the parameter list for a particular action is very long, you might want to define a route so that you can omit the keys from the request and hence shorten the url.
Let's say we have an employee controller with an index action that shows a table of employees with some additional data (such as age, department...) for each employee. The index action can take the following parameters:
a page parameter (required)
a sortby parameter (optional) which takes one column name to sort by (eg age)
a dept parameter (optional) which takes a name of a department and only shows the employees that are working in that department
We add the following route. Notice that when using this route, we cannot specify a dept parameter without specifying a sortby parameter first.
$route = new Zend_Controller_Router_Route(
'employee/index/:page/:sortby/:dept',
array(
'controller' => 'employee',
'action' => 'index')
);
If we would fetch these parameters in our action methods instead, we could avoid this problem (because the parameter keys are specified in the url):
http://example.com/employee/index/page/1/dept/staff
I might be looking at it the wrong way (or might not see the full potential of routing), but to me the only two reasons for using routes are:
If your urls don't conform to the traditional /module/controller/action pattern
If you want to make your urls more SEO-friendly
If your sole reason for using routes is to make use of the named parameters, then I think it's better to fetch these parameters in your action methods because of two reasons:
Keeping the number of routes at a minimum will reduce the amount of time and resources spent by the router
Passing in the parameter keys in the url allows us to make use of more complex urls with optional parameters.
Any thoughts or advice on this topic are more than welcome!
I'm writing a Backend System and I want to allow the users to change their email address.
I've written a custom validator to check if the email-address the user has entered already exists in my database.
Now I ran into a problem: The form is populated with the user data, so his email address is the default value of the email field. Now if the user submits the form, my validators throws an error, because (of course) this email address does already exist!
How can I solve this problem? Maybe a Validator is not the right approach to do this?
Or is there a solution to detect if the user changed the default value and fire the validator only in that case?
Hehe, that's a common problem running into validators the first time. The key is to remove that one id from the validator, inside your validator exclude the current user ID from the clause:
$validator = new Zend_Validate_Db_NoRecordExists(
array(
'table' => 'users',
'field' => 'email',
'exclude' => array(
'field' => 'id',
'value' => $id_to_edit
)
)
);
Edit: for further explanation as to what this does. It still grabs all the email adresses from the database and it still checks if there's a misconflict. If an email exists, it just ignores the email from id=$id_to_edit - so when the user changes its email but another user has that email already, the error gets thrown anyways!
hey all I'm using the Zend_Session_SaveHandler_DbTable Session handler and I was curious if anyone knows how to best add a custom field to the table that it stores the session data in? for example I'd like to be able to log the username of the person in the sessions table.
Anyone know if that's possible with the Zend_Session_SaveHandler_DbTable?
here's my set up code now..
$config = array(
'name' => 'session',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
Zend_Session::start();
i don' think it's possible, i have been searching for the same thing, but if you look at http://tig12.net/downloads/apidocs/zf/Session/SaveHandler/Zend_Session_SaveHandler_DbTable.class.html i don't see anything one could use,
i guess the way to do it, is to build another table, with session id as one column and any other columns you would want