Loading profile only with parameter without the need to key in Kohana 3.x - kohana-3

I'm new to Kohana 3.x. Would you like a website with Kohana with User profile style twitter. Example: https://twitter.com/maronems to load the profile is passed only paramentro maronems without the need to pass the key = parameter. Please can someone help me?

By "key = parameter" I assume you mean something like http://twitter.com?user=maronems right? This is ugly, we can do better.
Let's look at making your URLs look like http://twitter.com/maronems instead.
You'll want to look at Kohana's routing system.
Take a look at this route:
Route::set('username route', '<username>')
->defaults(array(
'controller' => 'Profile',
'action' => 'index',
));
Firstly, it's called username route, this is an aribitrary name,
but a good one because it's intent is clear.
Next look at the regex pattern <username>. This route is going to capture the username and store it in a variable called username.
Now notice that the route doesn't have to specify the controller and action. The routing system will get those from the default values. In this example you'll need a controller called Controller_Profile with an action called action_index.
So let's look at the controller now:
<?php
class Controller_Profile extends Controller {
function action_index()
{
echo 'Hello ' . $this->request->param('username');
}
}
Of course you shouldn't user echo like this in classes, but to illustrate the point, if you visit example.com/maronems you should see Hello maronems echoed out.

Related

Meteor's Iron Router: get query parameter on both Client and Server Side

there
In my application, if someone pass a parameter on the URL I want to do different things on the template.
I know I can get on server side a query string using this.params.query but how can I pass it to client OR get this value on client-side?
In my case I will send an optional redirect on the URL, and if it was passed, after the main task, my app will redirect the user to the url given. But I just know how to see redirect on server side, not on client, so this information get lost when I, for example, submit a form
Could you help me?
You can access the router params in your template with:
Router.current().params.query
Maybe in your route you can do like this:
onBeforeAction: function() {
Session.set("query", this.params.query);
this.next();
},
Then somewhere on the client you can make a helper like this:
Template.yourTemplateName.helpers({
query: function() {
return Session.get("query");
}
});
I'm not sure what to do with your redirect, but maybe it will work in the helper. So your html would be something like:
{{#if query}}{{query}}{{/if}}
And in the helper you could possibly replace "return Session.get("query")" with something like "Router.go('/wherever-you-want-to-go');". Or just write another helper to run in your html if the query is positive.

zend framework 2 changing layout in the controller

i want to change my layout in the controller. (i know how to change per module, but do need to change certain pages on my application, hence my need to use the controller).
i have done the following but it still render the default layout.
'template_map' => array(
'layout/homepage' => __DIR__ . '/../view/layout/homePageLayout.phtml'
)
controller
$viewModel = new ViewModel();
$viewModel->setTemplate('layout/homepage');
return $viewModel;
i noticed from this answer that i am supposed to use this instead
$this->layout('layout/different');
but the author does not clarify how that is supposed to be used. i.e instead of setTemplate is their a setLayout.
Thank you in advance for kind help.
i got the answer from this page.
all we need to do is this(same as above, accept that in the action we do the following)
public function someAction()
{
$this->layout("layout/homepage");
return new ViewModel(array(
));
}

Cakephp Security component blackholes delete post

I'm sending a delete post from an organisation page to a people controller like this:
$this->Form->postLink(__('Delete'),
array('controller'=> 'people', 'action' => 'delete',
$person['id'], 'referer' ),
null,
__('Are you sure you want to delete # %s?',
$person['firstname']));
In the people controller i am setting cross controller communication like this:
$this->Security->allowedControllers = array("people", "company");
Yet i still get sent to a black hole. Why?
Don't you have to write controllernames as a plural by convention?
So in this case you would set:
$this->Security->allowedControllers = array('peoples', 'companies');
And i don't think you need peoples in the array since that's the controller recieving the request. I am still learning cakePHP though, so i might be mistaking.

How to make sure a user can only see and access their own data in Yii

In Yii, is there a best way to make sure a user can only see and access their own data in Yii?
I thought an Admin should be able to see anything, but for now, I'll cross that bridge later.
Thanks
Look into scopes. Default scopes will be your friend:
http://www.yiiframework.com/doc/guide/1.1/en/database.ar#named-scopes
Because the defaultScopes array is inside of a function, you can also do conditional default scopes:
public function defaultScope()
{
$t=$this->getTableAlias(false,false);
if(Yii::app()->user->notAdmin()) {
return array(
'condition'=>"$t.<column_name> = :<columnName>",
'params'=>array(':<columnName>'=>Yii::app()->user->notAdmin),
);
}
else return array();
}
Edit: Note that this can get you in trouble down the road if you aren't careful. See this issue on the Yii site for more info.
There is no way Yii will do this for you, you'll do it on your own, but it's fairly straight forward.
You can consider scopes, or look into Relations and base them all on current user. For example, to get all posts by a user, you can do:
$posts = Post::model()->findAll(); //WRONG
$posts = Yii::app()->user->posts(); //RIGHT (Should define the relation in the User model)
Check out a solution which I wrote:
http://www.yiiframework.com/forum/index.php/topic/42735-restrict-users-to-only-editingdeleting-their-own-entries/page_gopid_237608#entry237608

Expressionengine hooks

I have a safecracker form that submits an entry. The form consists of title, url_title, and description. I want to create an extension hook that filters out certain words if they exist in the title of the entry.
I already have a function that take care of the cleaning function clean(){....}. I understand that we need to use an extension hook so we can clean the title upon saving the entry.
What extension hook do i need to use for that. can you give me a complete example of an extension hook. I'm very good with PHP but still new to hooks and how they should be implemented. I already read the EE documentation but still find some confusion of how a hook is used
First head over to http://pkg.io/ and get your base extension file.
You'll probably want to use the 'safecracker_submit_entry_start' hook to throw an error if unclean word is entered. The most important part of the extension is registering the method and hook you want to use, otherwise none of the code will run.
Your code should look something like this:
public function activate_extension()
{
// Setup custom settings in this array.
$this->settings = array();
$data = array(
'class' => __CLASS__,
'method' => 'clean', // point to the method that should run
'hook' => 'safecracker_submit_entry_end', // point to the hook you want to use to trigger the above method.
'settings' => serialize($this->settings),
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
}
Once the method has been called you can start your cleaning. Make sure you pass the safecracker object to your clean method when defining it. For example:
public function clean($sc){
print_r($sc);
}

Resources